- Create ConfigMaps for backup configuration and scripts - Define Secrets for S3 credentials - Implement Role and RoleBinding for access control - Set up a DaemonSet for running backup containers - Add a CronJob to schedule backups daily This commit establishes a comprehensive backup solution within the Kubernetes cluster, allowing for automated backups of specified directories to S3 storage. It includes necessary configurations and scripts to ensure proper execution and notification of backup status.
34 lines
1.0 KiB
YAML
34 lines
1.0 KiB
YAML
apiVersion: batch/v1
|
|
kind: CronJob
|
|
metadata:
|
|
name: node-backup-job
|
|
namespace: backup-system
|
|
spec:
|
|
# 每天凌晨2点运行
|
|
schedule: "0 2 * * *"
|
|
concurrencyPolicy: Forbid
|
|
jobTemplate:
|
|
spec:
|
|
ttlSecondsAfterFinished: 86400 # 1天后删除已完成的任务
|
|
template:
|
|
spec:
|
|
serviceAccountName: backup-service-account
|
|
nodeSelector:
|
|
#kubernetes.io/hostname: "vkvm-us1"
|
|
region: us
|
|
containers:
|
|
- name: backup-trigger
|
|
image: bitnami/kubectl:latest
|
|
command:
|
|
- /bin/sh
|
|
- -c
|
|
- |
|
|
# 创建触发文件到所有备份 Pod 中
|
|
for pod in $(kubectl get pods -n backup-system -l app=node-backup -o jsonpath='{.items[*].metadata.name}'); do
|
|
echo "触发 Pod $pod 执行备份"
|
|
sleep 60
|
|
kubectl exec $pod -n backup-system -- touch /tmp/backup-triggered
|
|
done
|
|
echo "所有节点备份已触发"
|
|
restartPolicy: OnFailure
|