ノート:
- このチュートリアルでは、Oracle Cloudへのアクセスが必要です。無料アカウントにサインアップするには、Oracle Cloud Infrastructure Free Tierの開始を参照してください。
- Oracle Cloud Infrastructureの資格証明、テナンシおよびコンパートメントに例の値を使用します。演習を完了するときは、これらの値をクラウド環境に固有の値に置き換えます。
Deploy Longhorn for Kubernetes on OKE
イントロダクション
Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE)は、完全に管理されたスケーラブルで可用性の高いサービスで、コンテナ化されたアプリケーションをクラウドにデプロイするために使用されます。You specify the compute resources that your applications require, and OKE provisions them on Oracle Cloud Infrastructure (OCI) in an existing OCI tenancy.Container Engine for KubernetesはKubernetesを使用します。これはオープンソースのシステムで、ホストのクラスタ間でコンテナ化されたアプリケーションのデプロイメント、スケーリングおよび管理を自動化します。
The OCI Block Volume service provides persistent, durable, and high-performance block storage for your data and OKE can utilize the block volumes as persistent disks for your Kubernetes environment and is fully managed by OKE.In case you want to be in complete control of the persistent storage solution you can deploy Longhorn on OKE and use it as your storage class.永続ボリューム、スケーリング、バックアップおよびスケジューリングを完全に制御できます。
目標
- Deploy and use Longhorn as the storage solution on OKE.
前提条件
-
Oracle Cloudテナンシへのアクセス。
-
テナンシに設定されているVirtual Cloud Network。
-
All the required policy set up for OKE.
Task 1: Create an OKE cluster
-
Log in to the OCI Console, navigate to Oracle Container Engine for Kubernetes and click Create.
-
「クラスタの作成」ウィザードで、「カスタム作成」をクリックします。

-
クラスタ名を指定し、使用するKubernetesバージョンを選択し、ウィザードの下部にある「次へ」をクリックします。

ノート:クラスタの作成を開始する前に、VCN、サブネットおよびルートを設定する必要があります
-
ネットワーク・タイプのいずれかを選択できます。The VCN native networking provides better performance.If you choose VCN native networking make sure your subnet has enough IP addresses available.

-
ノード・プールを構成し、目的のコンピュート・リソースを選択します。「拡張オプション」で、次のカスタム
cloud-initスクリプトを貼り付けます。
-
OKE does not provide an option to modify the node template, so in order to attach a block volume, you must run a
cloud-initscript at node initialization.スクリプトは、指定されたサイズとパフォーマンスのブロック・ボリュームを作成し、初期化時にノードにアタッチします。 -
Make sure to modify the
size_in_gbs(size of block storage to attach at init),vpus_per_gb(vpu per gb for the block storage attachment), andmode(attachment mode, PARA or ISCSI) variables in the script as per your need.
動的グループを作成し、このグループにブロック・ストレージへの管理アクセスを提供する必要があります。これにより、スクリプトでインスタンス・プリンシパル認証を使用できます。
cloud-initスクリプト:#!/bin/bash curl --fail -H "Authorization: Bearer Oracle" -L0 http://169.254.169.254/opc/v2/instance/metadata/oke_init_script | base64 --decode >/var/run/oke-init.sh bash /var/run/oke-init.sh echo "installing python3-pip , oci sdk\n" sudo yum install python3 -y sudo yum install python3-pip -y pip3 install oci pip3 install requests cat << EOF > pyscript.py #!/usr/bin/python import oci import requests size_in_gbs = 200 vpus_per_gb = 10 mode = 'PARA' device_path = "/dev/oracleoci/oraclevdb" signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner() compute_client = oci.core.ComputeClient({}, signer = signer) block_storage_client = oci.core.BlockstorageClient({}, signer = signer) def get_current_instance_details(): r = requests.get(url= 'http://169.254.169.254/opc/v1/instance') return r.json() def create_volume(block_storage, compartment_id, availability_domain, display_name: str): print("--- creating block volume ---") result = block_storage.create_volume( oci.core.models.CreateVolumeDetails( compartment_id=compartment_id, availability_domain=availability_domain, display_name=display_name, size_in_gbs = size_in_gbs, vpus_per_gb = vpus_per_gb ) ) volume = oci.wait_until( block_storage, block_storage.get_volume(result.data.id), 'lifecycle_state', 'AVAILABLE' ).data print('--- Created Volume ocid: {} ---'.format(result.data.id)) return volume def attach_volume(instance_id, volume_id,device_path): volume_attachment_response = "" if mode == 'ISCSI': print("--- Attaching block volume {} to instance {}---".format(volume_id,instance_id)) volume_attachment_response = compute_client.attach_volume( oci.core.models.AttachIScsiVolumeDetails( display_name='IscsiVolAttachment', instance_id=instance_id, volume_id=volume_id, device= device_path ) ) elif mode == 'PARA': volume_attachment_response = compute_client.attach_volume( oci.core.models.AttachParavirtualizedVolumeDetails( display_name='ParavirtualizedVolAttachment', instance_id=instance_id, volume_id=volume_id, device= device_path ) ) oci.wait_until( compute_client, compute_client.get_volume_attachment(volume_attachment_response.data.id), 'lifecycle_state', 'ATTACHED' ) print("--- Attaching complete block volume {} to instance {}---".format(volume_id,instance_id)) print(volume_attachment_response.data) # Call instance metadata uri to get current instace details instanceDetails = get_current_instance_details() print(instanceDetails) volume = create_volume(block_storage= block_storage_client, compartment_id= instanceDetails['compartmentId'], availability_domain=instanceDetails['availabilityDomain'], display_name= instanceDetails['displayName']) attach_volume(instance_id=instanceDetails['id'], volume_id=volume.id, device_path= device_path) EOF echo "running python script\n" chmod 755 pyscript.py ./pyscript.py echo "creating file system on volume\n" sudo /sbin/mkfs.ext4 /dev/oracleoci/oraclevdb echo "mounting volume\n" sudo mkdir /mnt/volume sudo mount /dev/oracleoci/oraclevdb /mnt/volume echo "adding entry to fstab\n" echo "/dev/oracleoci/oraclevdb /mnt/volume ext4 defaults,_netdev,nofail 0 2" | sudo tee -a /etc/fstab -
-
確認して「クラスタの作成」をクリックし、クラスタが使用可能になるまで待機します。
-
クラスタが使用可能になったら、「ノード・プール」、「ノード」の順に移動します。ノードが準備完了状態であることを確認し、任意のノードをクリックすると、インスタンスの詳細ページが開き、アタッチされたブロック・ボリュームに移動して、ブロック・ボリューム(
cloud-initスクリプトで説明したサイズおよびvpu)がインスタンスにアタッチされていることを確認できます。
タスク2: Longhornの設定
-
クラスタが使用可能になると、クラウド・シェルを使用してクラスタにアクセスし、「クラスタへのアクセス」をクリックして、クラウド・シェルでコマンドをコピーして実行できます。

-
kubectl get nodeを実行して、スケジュール可能なノードのリストを取得します。
-
Longhornがアタッチされたディスクを認識するには、Longhornのデフォルトのディスク設定の説明に従って、ラベルおよび注釈をノードに追加する必要があります。これを行うには、
patch.yamlファイルを作成してノードにパッチを適用します。metadata: labels: node.longhorn.io/create-default-disk: "config" annotations: node.longhorn.io/default-disks-config: '[ { "path":"/var/lib/longhorn", "allowScheduling":true }, { "path":"/mnt/volume", "allowScheduling":true } ]' -
各ノードに対して次のコマンドを実行します。
kubectl patch node <node name> --patch-file patch.yaml
-
describe nodeコマンドを実行して、ノードにパッチが適用されていることを確認します。
kubectl describe node <node name>
タスク3: Longhornのインストール
-
In this tutorial, we use Helm to deploy Longhorn on the OKE cluster.このドキュメントに記載されている手順(Helmを使用してインストール)に従います。
-
次のコマンドを実行してLonghornをデプロイします。
helm install longhorn longhorn/longhorn --namespace longhorn-system --create-namespace --version 1.3.2 --set defaultSettings.createDefaultDiskLabeledNodes=true
ノート:デプロイ時に
defaultSettings.createDefaultDiskLabeledNodesプロパティをtrueに設定します。これにより、longhornは、以前に提供したアタッチ・ブロック・ボリューム構成を使用するようになります。 -
ポッドが作成され、実行されていることを確認します。

-
To enable the UI for a better view of Longhorn and its administration, install the Ingress Controller as mentioned in this document: Example: Setting Up an Ingress Controller on a Cluster.
-
Create an
ingress.yamlfile to expose the Longhorn UI.apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: longhorn-ingress namespace: longhorn-system annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - http: paths: - path: / pathType: Prefix backend: service: name: longhorn-frontend port: number: 80 -
Run
kubectl apply -f ingress.yamlto expose the Longhorn UI using Ingress gateway.
-
次のコマンドを実行してゲートウェイURLを取得します。
kubectl get ingress -n longhorn-system.
-
Open the IP address from a browser to access the Longhorn Console and confirm it is live.

ストレージが使用可能であり、使用する準備ができていることがわかります。
タスク4: スケール・ロンゴーン
Longhornを使用すると、kubernetesデプロイメント用のストレージ・ソリューションを完全に制御できますが、longhornのスケーリングは依然として手動プロセスであり、Longhorn設定をスケーリングできる3つの方法があります。
-
アタッチされたブロック・ボリュームのサイズまたはパフォーマンス・ユニットの増加: これは手動プロセスであり、各ブロック・ボリュームを個別にスケーリングし、ノード上でいくつかのスクリプトを実行してストレージを拡張する必要があります。詳細は、ボリュームのサイズ変更を参照してください。
-
より多くのボリュームのアタッチ: ボリュームを手動で作成してノードにアタッチする必要があります。
-
ノードを増やすことでクラスタをスケーリングします。すでに
cloud-initスクリプトが提供されているため、ブロック・ボリュームが作成され、ノードにアタッチされます。Longhornが接続されたストレージを認識できるように、タスク2.3で説明したように、ノードにパッチを適用する必要があります。
ノート:スクリプトを変更して、必要な数のブロック・ボリュームを単一ノードにアタッチできます。
関連リンク
確認
- 著者 - Mayank Kakani(OCI Cloud Architect)
その他の学習リソース
docs.oracle.com/learnの他のラボをご覧いただくか、Oracle Learning YouTubeチャネルで無料のラーニング・コンテンツにアクセスしてください。また、education.oracle.com/learning-explorerにアクセスしてOracle Learning Explorerになります。
製品ドキュメントは、Oracle Help Centerを参照してください。
Deploy Longhorn for Kubernetes on OKE
F76576-02
December 2023
Copyright © 2023, Oracle and/or its affiliates.