PVCスナップショットのスケジュール設定
KubernetesのPV Snapshot機能に加えて、FPT CloudはKubernetes上のCronJobを使用したスナップショットのスケジュール機能を提供しています。
1. PVCスナップショット用CronJobスケジュールの設定
ステップ1: 対応するServiceAccountを適用して、KubernetesクラスターのCronJobに必要な権限を付与します:
apiVersion: v1
kind: ServiceAccount
metadata:
name: snapshot-sa
namespace: default #or any other namespace that you want to deploy the cronjob
ステップ2: 作成したServiceAccountに権限を付与するためのClusterRoleBindingを適用します。subjectsには、上記で作成した対応するnamespaceのすべてのServiceAccountを含める必要があります:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: grant-snapshot-sa-admin
subjects:
- kind: ServiceAccount
name: snapshot-sa
namespace: default #or any other namespace that you want to deploy the cronjob
- kind: ServiceAccount
name: snapshot-sa
namespace: namespace1 #if user wants to have multiple cronjob in multiple namespace
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
以下のコマンドでClusterRoleBindingを確認できます:
kubectl get clusterrolebinding grant-snapshot-sa-admin -oyaml
ステップ3: 以下の形式でCronJobを適用し、PVCスナップショットを自動スケジュールします:
apiVersion: batch/v1
kind: CronJob
metadata:
name: pvc-snapshot #or any other name that you want to set
namespace: default #or any other namespace that you want to deploy the cronjob, but must be in the same namespace with ServiceAccount and ClusterRoleBinding
spec:
schedule: "0 * * * *" #Adjust this (minute hour day(month) month day(week))
timeZone: "Asia/Saigon"
jobTemplate:
spec:
template:
spec:
serviceAccountName: snapshot-sa #Remember to match the name of ServiceAccount that deployed previously
containers:
- name: pvc-snapshot
image: registry.fke.fptcloud.com/xplat-fke/snapshot-pvc:v0.1.0
env:
- name: PVC_NAME
value: "your-pvc-name" #name of the PVC that you want to apply Cronjob to
- name: NAMESPACE
value: "your-pvc-namespace" #namespace of the above PVC
restartPolicy: OnFailure
2. PVCスナップショット用CronJobスケジュールの削除
PVCのスナップショット自動スケジュールが不要になった場合は、作成済みの対応するCronJobを削除するだけで解除できます。
スナップショット一覧表示時の出力例:
kubectl get volumesnapshots.snapshot.storage.k8s.io -A
NAMESPACE NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
example wp-pv-claim-example-2412020736 true wp-pv-claim 20Gi csi-cinder-snapclass snapcontent-045fe85e-7471-4bfb-9a55-2ed2ed2263dd 64m 64m
example wp-pv-claim-example-2412020836 true wp-pv-claim 20Gi csi-cinder-snapclass snapcontent-fd1333bc-70f6-417f-a91d-10349aa0647d 4m11s 4m11s
スナップショット名wp-pv-claim-example-2412020736の意味:
wp-pv-claim:PVC名example:namespace名2412020736:24(年)、12(月)、02(日)、07(時)、36(分)(UTC+0)
注意事項: 1つのPVCに設定できるCronJobは1つのみです。複数のPVCを同時にスケジュールしたい場合、または1つのPVCに複数のスケジュールを設定したい場合は、それぞれ別のCronJobを作成してください。
新しいJobが実行されると、PVCスナップショットの作成を自動化するためのPodが作成されます。以下のコマンドで確認できます:
kubectl get volumesnapshots.snapshot.storage.k8s.io -n <namespace>kubectl get jobs.batch -n <namespace>
FPT Cloud提供のイメージにはRetention機能が含まれていないため、ディスクストレージクォータが満杯にならないよう、スナップショットを手動で削除する必要があります。