Post

Kubernetes CronJob for APISIX ETCD Backup

Kubernetes CronJob for APISIX ETCD Backup

🚀 Kubernetes CronJob for APISIX ETCD Backup

This guide explains how to configure a Kubernetes CronJob to back up APISIX’s ETCD data and transfer it to a remote server via SSH. Show project on GitHub

🛠️ Configuration

Modify the relevant sections in the etcd-backup-cronjob.yaml file:

1
2
3
LOCAL_SERVER="10.42.0.200"
LOCAL_USER="etcdbackup"
LOCAL_PATH="/home/etcdbackup/apisix-etcd-backup"

and apisix etcd pod names;

1
apisix-main-etcd-0 apisix-main-etcd-1 apisix-main-etcd-2

🔑 Generating an SSH Key Pair

1
ssh-keygen

🔐 Adding the Private Key to Kubernetes

1
kubectl create secret generic sftp-secret --from-file=id_rsa=./path/to/privatekey -n yournamespace

🖥️ Configuring SSH Access on the Remote Server

1
cat path/to/publickey >> /home/$USER/.ssh/authorized_keys
Example Public KeyExample Private Key
ssh-ed25519 AAAAC… mustafav@vurulkan.local—–BEGIN OPENSSH PRIVATE KEY—– b3BlbnNzaC1… —–END OPENSSH PRIVATE KEY—–

📦 Deploying Kubernetes Resources

Apply the Service Account

1
kubectl apply -f kubernetes-service-account.yaml -n yournamespace

Deploy the CronJob

1
kubectl apply -f etcd-backup-cronjob.yaml -n yournamespace

✅ Verify the CronJob Execution

Manually trigger the CronJob and check the logs:

1
2
kubectl create job --from=cronjob/etcd-backup-cronjob -n yournamespace
kubectl logs -l job-name=etcd-backup-cronjob -n yournamespace
This post is licensed under CC BY 4.0 by the author.