Contents

Kubernetes Backup and Restore

Backup Candidate

Resource Configuration

Resource Configuration
YAML Files

Imperative

Create Resource

1
2
3
kubectl create namespace new-namespace
kubectl create secret
kubectl create configmap

Backup

1
2
# Backup All Resources
kubectl get all --all-namespaces -o yaml > all-deploy-services.yaml

Declarative

Recommendation
Save to GitHub and manage with a team!

VELERO

VELERO
Velero is an open source tool to safely backup and restore, perform disaster recovery, and migrate Kubernetes cluster resources and persistent volumes.

ETCD Cluster

ETCD Cluster
ETCD Snapshots

ETCD Information

ETCD Service
1
cat /etc/systemd/system/etcd.service
ETCD Version

Image Version

1
kubectl -n kube-system describe pod etcd-master | grep -i image
ETCD Address
1
kubectl -n kube-system describe pod etcd-controlplane | grep -i listen-client

Backup And Restore ETCD

Create A Snapshot
1
ETCDCTL_API=3 etcdctl snapshot save snapshot.db
Status Of Snapshot
1
ETCDCTL_API=3 etcdctl snapshot status snapshot.db
1
2
3
4
5
ETCDCTL_API=3 etcdctl snapshot save snapshot.db \
    --endpoints=https://127.0.0.1:2379 \
    --cacert=/etc/etcd/ca.crt \
    --cert=/etc/etcd/etcd-server.crt \
    --key=/etc/etcd/etcd-server.key
Restore ETCD
Stop kube-apiserver
1
service kube-apiserver stop
Restore Snapshot
Sample
1
2
3
4
5
ETCDCTL_API=3 etcdctl snapshot restore snapshot.db \
    --data-dir /var/lib/etcd-from-backup \
    --initial-cluster master-1=https://192.168.5.11:2380,master-2=https://192.168.5.12:2380 \
    --initial-cluster-token etcd-cluster-1 \
    --initial-advertise-peer-urls https://${INTERNAL_IP}:2380
Restore snapshot with --data-dir
1
2
ETCDCTL_API=3 etcdctl snapshot restore /opt/snapshot-pre-boot.db \
    --data-dir /var/lib/etcd-from-backup
Change the etcd.yaml
1
vi /etc/kubernetes/manifests/etcd.yaml
Change the path
1
2
3
4
5
  volumes:
    - hostPath:
        path: /var/lib/etcd-from-backup
        type: DirectoryOrCreate
      name: etcd-data
Reload Daemon
1
systemctl daemon-reload
Start etcd
1
service etcd restart
Start kube-apiserver
1
service kube-apiserver start

Persistence Volumes

Persistence Volumes
Disk