- Take me to Video Tutorial
In this section, we will take a look at backup and restore methods
-
Imperative way
-
Declarative Way (Preferred approach)
apiVersion: v1 kind: Pod metadata: name: myapp-pod labels: app: myapp type: front-end spec: containers: - name: nginx-container image: nginx
-
A better approach to backing up resource configuration is to use query the kube-apiserver using 'kubectl' or by accessing the API server directly and save all resource configurations for all objects created on the cluster has a copy.
$ kubectl get all --all-namespaces -o yaml > all-deploy-services.yaml (only for few resource groups) -
There are many other resource groups that must be considered. There are tools like
ARKor now calledVeleroby Heptio that can do this for you.
-
The ETCD cluster stores information about the state of our cluster. So information about the cluster itself, the nodes and every other resources as created within the cluster are store here.
-
So, instead of backing up resources as before, you may choose to backup the ETCD cluster itself.
-
While configuring ETC, we have configured where all the data would be stored in the data directory (/var/lib/etcd)
-
You can take a snapshot of the etcd database by using
etcdctlutility snapshot save command.$ ETCDCTL_API=3 etcdctl snapshot save snapshot.db$ ETCDCTL_API=3 etcdctl snapshot status snapshot.db
-
To restore etcd from the backup at later in time. First stop kube-apiserver service
$ service kube-apiserver stop -
Run the etcdctl snapshot restore command
-
Update the etcd service
-
Reload system configs
$ systemctl daemon-reload -
Restart etcd
$ service etcd restart -
Start the kube-apiserver
$ service kube-apiserver start
$ ETCDCTL_API=3 etcdctl --endpoints=https://[127.0.0.1]:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/etcd-server.crt \
--key=/etc/kubernetes/pki/etcd/etcd-server.key snapshot save /tmp/snapshot.db