Backing up and restoring etcd
So here I’m going to go through backing up etcd on a kubernetes cluster.
The reason I’ve done this before is for the Kubernetes Certified Administrator (CKA) exam where you would need to know how to do this. In managed clusters like GKE then you probably will never need to interact with etcd.
There’s a few steps involved in Backup:
- save the snapshot Restore:
- stop all cluster components
- restore the snapshot
- restart all cluster components
Setup
The first thing you’ll want to do before all this is ssh onto the master node of the cluster. The master node is where things like etcd are configured.
We’re going to be using etcdctl to back up etcd in this tutorial. You can make sure it’s installed by running etcdctl version. This will return the etcdctl version and the API version which should be the same. If this command does not work then you can either install etcdctl or even see if etcd is even running on the cluster by seeing if there’s any etcd pods running
Authentication
Another thing you may need to do before continuing on is you may need to authenticate with the cluster. If you find the etcdctl commands hanging or not completing then this is probably the reason. One way of authenticating is by passing in the certs used for etcd. These are usually stored on the master node and you can find the location by looking at the etcd.yaml file. So for example
> cat /etc/kubernetes/manifests/etcd.yaml
...
spec:
containers:
- command:
- etcd