PVCスナップショット削除のスケジュール設定
FPT Cloudでは、PVC名、対応するnamespace、および時間または日数で指定した保持期間に基づいて、PVCスナップショットの自動削除をスケジュールする機能を提供しています。
PVCスナップショットクリーンアップ用CronJobスケジュールの設定
ステップ1: 対応するServiceAccountを適用して、KubernetesクラスターのCronJobに必要な権限を付与します:
apiVersion: v1
kind: ServiceAccount
metadata:
name: cleanup-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-cleanup-snapshot-sa-admin
subjects:
- kind: ServiceAccount
name: cleanup-snapshot-sa
namespace: default #or any other namespace that you want to deploy the cronjob
- kind: ServiceAccount
name: cleanup-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-cleanup-snapshot-sa-admin
ステップ3: 以下の形式でCronJobを適用し、PVCスナップショットを自動削除します:
apiVersion: batch/v1
kind: CronJob
metadata:
name: cleanup-snapshots
spec:
schedule: "0 2 * * *" #Adjust this (minute hour day(month) month day(week))
timeZone: "Asia/Saigon"
jobTemplate:
spec:
template:
spec:
serviceAccountName: cleanup-snapshot-sa #match with service account name
containers:
- name: snapshot-cleanup
image: registry.fke.fptcloud.com/xplat-fke/cleanup-snapshot-pvc:v0.1.0
env:
- name: NAMESPACE
value: "your-pvc-namespace" #Replace with your PVC namespace
- name: PVC_NAME
value: "your-pvc" #Replace with your PVC name
- name: RETENTION_MAX
value: "7" #or any int > 0
- name: RETENTION_UNITS
value: "days" #or "hours"
restartPolicy: OnFailure
PVCスナップショットクリーンアップCronJobの削除
PVCのスナップショット自動削除スケジュールが不要になった場合は、作成済みの対応するCronJobを削除するだけで解除できます。