※本記事は、Seshadri Dehalisan による “Backing up your OKE environment with Velero” を翻訳したものです。
今やKubernetesは、コンテナ化したアプリケーションをデプロイメントする企業にとって、究極のソリューションになりました。オラクルでは、そのKubernetes向けにOracle Container Engine for Kubernetes(OKE)を提供しています。これは、Oracle Cloud Infrastructure(OCI)にてコンテナ化したワークロードをデプロイするための、フルマネージドで、スケーラブルで、可用性の高いサービスになります。このOKEにより、コンテナ化したワークロードを大規模かつスムーズに実行できるようになりますが、その一方で、ディザスタ・リカバリやバックアップ要件といった重要なワークロードを実行するための基本的なビジネス要件は、顧客ニーズと密接な関係があります。
ディザスタ・リカバリおよびバックアップソリューションを堅牢なものにするには、クラスタのメタデータ定義のバックアップと、Kubernetesクラスタの永続データのバックアップ機能の提供が必要です。現在市場で入手できるテクノロジーはさまざまありますが、このガイドでは、オープンソース・ツールのVeleroを使用して、OKEクラスタのバックアップにソリューションを提供することを目指します。また、このVeleroを利用したソリューションを拡大させれば、ディザスタ・リカバリや、コンテナ化したKubernetesクラスタを他のプロバイダからOCIへ移行することも可能になります。さらにこちらのブログにて説明されているとおり、バックアップおよびディザスタ・リカバリのユースケースに、OKEと合わせてKastenを使用することも可能です。
Veleroのデプロイメント・プロセス
Veleroでは、Resticを使用して永続ボリュームをバックアップします。Resticは軽量なクラウド・ネイティブのバックアップ・プログラムで、バックアップの分野で幅広く採用されています。Veleroでは、デプロイメント、Restic DaemonSets、およびカスタム・リソース定義を含め、Kubernetesオブジェクトを作成することで、バックアップおよびリストアを可能にします。
インストール条件
OKEのクラスタおよびkubectlへのアクセスをローカルにインストールします。
kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
10.0.0.4 Ready node 2d21h v1.18.10 10.0.0.4
Oracle Linux Server 7.9 5.4.17-2036.100.6.1.el7uek.x86_64 docker://19.3.11
10.0.0.5 Ready node 2d21h v1.18.10 10.0.0.5
Oracle Linux Server 7.9 5.4.17-2036.100.6.1.el7uek.x86_64 docker://19.3.11
クライアント環境(Linux、Mac、Windows)によって、インストール・ステップは異なります。またOCI Cloud ShellからVeleroを先にインストールしておくことも可能です。
Macでは、以下のコマンドにてVeleroをインストールできます。
brew install velero
Veleroをローカルにインストールできたら、以下のように、Veleroにて適切なKubernetesリソースを作成できます。
velero install \
--provider aws \
--bucket velero \
--prefix oke \
--use-restic \
--secret-file /Users/xxxx/velero/velero/credentials-velero \
--backup-location-config s3Url=https://tenancyname.compat.objectstorage.region.oraclecloud.com,region=region,s3ForcePathStyle="true" \
--plugins velero/velero-plugin-for-aws:v1.1.0 \
--use-volume-snapshots=false
OCI Object StorageはS3互換であるため、上のコード・ブロックでもわかるとおり、プロバイダおよびオブジェクト・ストレージでは、バックアップ目的で、AWS S3リファレンスを使用します。この特徴により、EKSワークロードのOCIへのシームレスな移行も可能になります。またuse-resticパラメータにより、resticを使用して永続ボリュームをバックアップすることが可能になります。インストールが完了すると、Veleroにて少数のKubernetesリソースが作成されますが、これらはデフォルトでvelero名前空間に作成されます。
secret-fileは、VeleroにてOCI Object Storageのバケットへのバックアップに使用される資格証明を参照します。Managing User Credentialsに記載されているとおり、これらの資格情報は顧客秘密キーとして作成する必要があります。またオブジェクト・ストレージにバックアップするユーザー・プロファイルは、バックアップが記述されるバケットを管理できるものである必要があります。
資格証明ファイルの例は以下のとおりです。
aws_access_key_id=40xxxxxxxxxxxxxxxxxxxxxxxxxxxxxa32f8494a
aws_secret_access_key=YyuSZxxxxxxxxxxxxxxxxxxxxxxxxxxxxxRDYzNnv0c=
kubectl get pods --namespace velero -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
restic-2lp99 1/1 Running 2 23h 10.234.0.26 10.0.0.5
restic-6jz9k 1/1 Running 0 23h 10.234.0.137 10.0.0.4
velero-84f5449954-46hnk 1/1 Running 0 23h 10.234.0.136 10.0.0.4
Veleroを使用できるようになったので、次は永続ボリューム要求を使用する簡単なNginxデプロイメントを作成しましょう。
- ストレージ・クラスを作成します(クラスタ・リソース)。
- 永続ボリュームを作成します(クラスタ・リソース)。
- ポッドおよび永続ボリューム要求(PVC)が入る名前空間を作成します。
- PVCを作成します(名前空間はスコープ済み)。
- ポッドを作成します。
ストレージ・クラスを作成する
ストレージ・クラスを作成するには、以下のコマンドを実行します。
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: oci-fss1
provisioner: oracle.com/oci-fss
parameters:
# Insert mount target from the FSS here
mntTargetId: ocid1.mounttarget.oc1.us_ashburn_1.aaaaaa4np2sra5lqmjxw2llqojxwiotboaww25lxxxxxxxxxxxxxiljr
ストレージ・クラスでは、OCI File Storageサービスのマウント・ターゲットがKubernetesに提供されています。File Storageサービスの詳細については、こちらの資料を参照してください。
必要な名前空間を作成する
必要な名前空間を作成するには、以下のコマンドを実行します。
kubectl create namespace testing
永続ストレージを作成する
永続ストレージを作成するには、以下のコマンドを実行します。
apiVersion: v1
kind: PersistentVolume
metadata:
name: oke-fsspv1
spec:
storageClassName: oci-fss1
capacity:
storage: 100Gi
accessModes:
- ReadWriteMany
mountOptions:
- nosuid
nfs:
# Replace this with the IP of your FSS file system in OCI
server: 10.0.0.3
# Replace this with the Path of your FSS file system in OCI
path: /testpv
readOnly: false
永続ボリューム要求を作成する
永続ボリューム要求を作成するには、以下のコマンドを実行します。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: oke-fsspvc1
spec:
storageClassName: oci-fss1
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
volumeName: oke-fsspv1
ポッドがPVCを使用していること、およびFile Storageがポッドにて利用可能で、またマウントされていることを確認しましょう。
kubectl exec -it oke-fsspod3 -n testing -- bash
root@oke-fsspod3:/# mount |egrep -i nfs
10.0.0.3:/testpv on /usr/share/nginx/html type nfs
root@oke-fsspod3:/# cd /usr/share/nginx/html
root@oke-fsspod3:/usr/share/nginx/html# ls -lrt *.dmp|wc -l 65
root@oke-fsspod3:/usr/share/nginx/html# ls -lrt *.dmp|head -5
-rw-r--r--. 1 root root 75853 Feb 8 04:37 randomfile1.dmp
-rw-r--r--. 1 root root 77341 Feb 8 04:37 randomfile2.dmp
-rw-r--r--. 1 root root 76599 Feb 8 04:37 randomfile3.dmp
-rw-r--r--. 1 root root 75066 Feb 8 04:38 randomfile4.dmp
-rw-r--r--. 1 root root 75008 Feb 8 04:38 randomfile5.dmp
ボリュームのアノテーション
Veleroでは、ポッドにはボリューム名がアノテーションとして付与されることが前提になります。ボリューム名は以下のコマンドにて追加できます。
kubectl -n testing annotate pod/oke-fsspod3 backup.velero.io/backup-volumes=oke-fsspv1
バックアップ・プロセス
クラスタをバックアップする
OKEクラスタをバックアップするには、以下のコマンドを発行します。
./velero backup create backup-full-cluster-demo --default-volumes-to-restic=true
Backup request "backup-full-cluster-demo" submitted successfully.
Run `velero backup describe backup-full-cluster-demo` or `velero backup logs backup-full-cluster-demo` for more details.
./velero backup describe backup-full-cluster-demo
Name: backup-full-cluster-demo
Namespace: velero
Labels: velero.io/storage-location=default
Annotations: velero.io/source-cluster-k8s-gitversion=v1.18.10
velero.io/source-cluster-k8s-major-version=1
現行のリリースでは、Veleroは、永続ボリュームの動的プロビジョニングと合わせてリストアしようとします。したがって、静的に作成された永続ボリュームは別にバックアップする必要があります。このタスクを完了するには、以下のコマンドを使用します。
./velero backup create backup-pv-only-demo --default-volumes-to-restic=true --include-resources pve
Backup request "backup-pv-only-demo" submitted successfully.
Run `velero backup describe backup-pv-only-demo` or `velero backup logs backup-pv-only-demo` for more details.
% ./velero backup describe backup-pv-only-demo --details
Name: backup-pv-only-demo
Namespace: velero
Labels: velero.io/storage-location=default
Annotations: velero.io/source-cluster-k8s-gitversion=v1.18.10
velero.io/source-cluster-k8s-major-version=1
velero.io/source-cluster-k8s-minor-version=18
Phase: Completed
リストア
リストアのケースを作成するため、PVC、ポッド、名前空間、クラスタ・スコープの永続ボリュームを削除してみましょう。これらが削除される要因としては、偶発的な損失、オペレーターのミス、ディザスタ・リカバリなどがあります。データがリストアされていることを確認するため、ポッドにて作成されたランダム・ファイルも削除しましょう。
kubectl exec -it oke-fsspod3 -n testing -- bash
root@oke-fsspod3:/# cd /usr/share/nginx/html
root@oke-fsspod3:/usr/share/nginx/html#
root@oke-fsspod3:/usr/share/nginx/html# ls -lrt *.dmp |wc -l
65
root@oke-fsspod3:/usr/share/nginx/html# rm *.dmp
root@oke-fsspod3:/usr/share/nginx/html# ls -lrt *.dmp |wc -l
ls: cannot access ’*.dmp’: No such file or directory
0
ポッドと関連するリソースを削除するには、以下のコマンドを実行します。
~ % kubectl delete pod oke-fsspod3 -n testing
pod "oke-fsspod3" deleted
~ % kubectl delete pvc oke-fsspvc1 -n testing
persistentvolumeclaim "oke-fsspvc1" deleted
~ % kubectl delete namespace testing
namespace "testing" deleted
~ % kubectl delete pv oke-fsspv1
persistentvolume "oke-fsspv1" deleted
velero % kubectl get pv
No resources found
ポッドと永続ボリュームが削除されたので、次はリストアです。既存のバックアップを確認し、以下のとおり適切なリストア・コマンドを発行しましょう。
% velero % ./velero backup get
NAME STATUS ERRORS WARNINGS CREATED EXPIRES STORAGE LOCATION SELECTOR
backup-full-cluster-demo Completed 0 0 2021-02-07 21:46:23 -0600 CST 28d default
backup-full-cluster-demo-1 Completed 0 0 2021-02-07 21:52:25 -0600 CST 28d default
backup-full-cluster-demo-2 Completed 0 0 2021-02-07 22:44:09 -0600 CST 29d default
backup-pv-demo-1 Completed 0 0 2021-02-07 21:55:08 -0600 CST 29d default
backup-pv-demo-2 Completed 0 0 2021-02-07 22:46:23 -0600 CST 29d default
永続ボリュームをリストアする
永続ボリュームのリストアには、以下のコマンドを使用します。
velero % ./velero restore create --from-backup backup-pv-demo-2
Restore request "backup-pv-demo-2-20210208215719" submitted successfully.
Run `velero restore describe backup-pv-demo-2-20210208215719` or `velero restore logs backup-pv-demo-2-20210208215719` for more details.
velero % ./velero restore describe backup-pv-demo-2-20210208215719
Name: backup-pv-demo-2-20210208215719
Namespace: velero
Labels:
Annotations:
Phase: Completed
Started: 2021-02-08 21:57:22 -0600 CST
Completed: 2021-02-08 21:57:23 -0600 CST
Backup: backup-pv-demo-2
Namespaces:
Included: all namespaces found in the backup
Excluded:
Resources:
Included: *
Excluded: nodes, events, events.events.k8s.io, backups.velero.io, restores.velero.io, resticrepositories.velero.io
Cluster-scoped: auto
Namespace mappings:
Label selector:
Restore PVs: auto % kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE oke-fsspv1 100Gi RWX Retain Available testing/oke-fsspvc1 oci-fss1 31s
続いてクラスタをリストアします。リストアする必要のあるポッドは1つのみですが、この例では、クラスタのリストア機能をわかりやすく示すため、フル・クラスタ・リストアを発行します。
% ./velero restore create --from-backup backup-full-cluster-demo-2
Restore request "backup-full-cluster-demo-2-20210208220018" submitted successfully.
Run `velero restore describe backup-full-cluster-demo-2-20210208220018` or `velero restore logs backup-full-cluster-demo-2-20210208220018` for more details.
% ./velero restore describe backup-full-cluster-demo-2-20210208220018
Name: backup-full-cluster-demo-2-20210208220018
Namespace: velero
Labels:
Annotations:
Phase: Completed
Started: 2021-02-08 22:00:20 -0600 CST
Completed: 2021-02-08 22:01:04 -0600 CST
% kubectl get pods --namespace testing -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
oke-fsspod3 1/1 Running 0 12m 10.234.0.30 10.0.0.5
% kubectl get pods --namespace testing -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
oke-fsspod3 1/1 Running 0 12m 10.234.0.30 10.0.0.5
% kubectl exec -it oke-fsspod3 -n testing -- bash root@oke-fsspod3:/# cd /usr/share/nginx/html root@oke-fsspod3:/usr/share/nginx/html# ls -lrt *.dmp |wc -l 65
前のブロックにて確認したとおり、ポッドおよび関連する永続ボリュームがリストアされています。このプロセスが機能することは、k8s v1.18.10およびv1.17.13にてテスト済みです。詳細はこちらの資料を参照してください。
このプロセスを他のユースケースへ拡大する
このブログは、永続ボリュームを使用したOKEの基本的なバックアップおよびリカバリにフォーカスしています。Veleroでは、他の大半のバックアップ・ツールと同様、定期的に自動バックアップが実行されるよう設定することもできます。また以下のようなユースケースにもVeleroを使用できます。
- オブジェクト・ストレージを別のリージョンに変更し、OKEクラスタに対するリージョンごとのディザスタ・リカバリを可能にする。(このプロセスでは、組織のデータ・レジデンシー要件に従う必要があります)
- OCIのパフォーマンスとセキュリティ・レベルの高さ、および価格的メリットを享受できるよう、他のクラウド・プロバイダからOKEへKubernetesのデプロイメントを移行する。
- オンプレミスのKubernetesから移行する。
Oracle Cloud Container Engine for Kubernetesが持つ堅牢性とスケーラビリティに、Veleroのディザスタ・リカバリ機能を組み合わせることで、より本番環境に即したKubernetesプラットフォームの使用が可能になります。
