我们使用 mysql 数据库在 k8s(GCP) 中部署一个 laravel 项目。现在我想在 cronjob 的帮助下不时备份这个数据库,我关注了一篇文章 ,但我无法创建备份文件。但是,根据文章,我们需要在GCP中创建存储桶和服务帐户
它工作正常,但存储桶中没有备份文件。
cronjob.yaml 文件
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: backup-cronjob
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: backup-container
image: gcr.io/thereport/abcd
env:
- name: DB_NAME
valueFrom:
configMapKeyRef:
name: backup-configmap
key: db
- name: GCS_BUCKET
valueFrom:
configMapKeyRef:
name: backup-configmap
key: gcs-bucket
- name: DB_HOST
valueFrom:
secretKeyRef:
name: backup
key: db_host
- name: DB_USER
valueFrom:
secretKeyRef:
name: backup
key: username
- name: DB_PASS
valueFrom:
secretKeyRef:
name: backup
key: password
- name: GCS_SA
valueFrom:
secretKeyRef:
name: backup
key: thereport-541be75e66dd.json
args:
- /bin/bash
- -c
- mysqldump --u root --p"root" homestead > trydata.sql; gcloud config set project thereport; gcloud auth activate-service-account --key-file backup; gsutil cp /trydata.sql gs://backup-buck
restartPolicy: OnFailure