You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Prerequisites

Within the cluster nodes that act only as etcd, the executable files are probably already present.

To be able to back up a k8s cluster, first we need the executable file etcdctl, downloadable from here (choose the appropriate release). After that, unpack the archive file (this results in a directory containing the binaries) and add the executable binaries to your path (i.e. /usr/local/bin)

Download binary
# For example, let's download release 3.5.4
$ wget https://github.com/etcd-io/etcd/releases/download/v3.5.4/etcd-v3.5.4-linux-amd64.tar.gz
$ tar xzvf etcd-v3.5.4-linux-amd64.tar.gz
$ sudo cp etcd-v3.5.4-linux-amd64/etcdctl /usr/local/bin/
$ etcdctl version
etcdctl version: 3.5.4
API version: 3.5

Once we have the executable file, we need the certificates to be able to communicate with the etcd node(s). If you don't know the location of the certificates, you can retrieve it using the grep command in the /etc/kubernetes folder on the master node. Save the location of the certificates in the following environment variables

etcd certificates
# Insert the following lines inside the ".bashrc" file, then use "$ source .bashrc" to apply the changes
export ETCDCTL_CERT=/<path>/cert.pem
export ETCDCTL_CACERT=/<path>/ca.pem
export ETCDCTL_KEY=/<path>/key.pem

Save and Restore

If you have an etcd cluster, you can select only one node, otherwise you get the error snapshot must be requested to one selected node, not multiple.

Take a snapshot of the etcd datastore using the following command, which generates the file <snapshot_file>

Save snapshot
$ etcdctl snapshot save <snapshot_file> --endpoints=<endpoint>:<port>
# Instead of <endpoint> you can substitute a hostname or an IP
$ etcdctl snapshot save snapshot.db --endpoints=etcd1:2379
$ etcdctl snapshot save snapshot.db --endpoints=192.168.100.88:2379
  • No labels