Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Doel
This task is in almost every CKA exam. You take a snapshot of etcd with the right certificates, delete things on purpose, restore the snapshot into a new data directory and point the etcd static pod to it. At the end the deleted objects are back. You also check the certificate dates and drain a node safely.
Voordat je begint
- A cluster made with kubeadm (see the chapter Build a cluster with kubeadm), or a practice cluster like killercoda.
- On the control plane node:
etcdctl(packageetcd-client) andetcdutlif your version has it. Run the etcd commands as root. - Create test objects:
kubectl create ns backup-test && kubectl -n backup-test create deploy web --image=nginx --replicas=2.
Taken
Vink een taak aan als hij klaar is. Alleen je browser onthoudt dit.
- Find the etcd endpoint and the paths of the CA, server certificate and key in
/etc/kubernetes/manifests/etcd.yaml. - Save a snapshot to
/opt/backup/etcd-$(date +%F).dband check its status (hash, revision, number of keys). - Delete the namespace
backup-test. - Restore the snapshot into
/var/lib/etcd-restore. - Change the etcd static pod to use the new data directory. Wait until the API server works again.
- Check that
backup-testand the deploymentwebare back. - Show when the cluster certificates expire.
- Drain a worker node (if you have one) for maintenance and bring it back.
Controleer je werk
ls -lh /opt/backup/
kubectl get ns backup-test
kubectl -n backup-test get deploy web
grep -A2 "name: etcd-data" /etc/kubernetes/manifests/etcd.yaml
kubeadm certs check-expiration- The snapshot file is a few MB, and
snapshot statusshowed a hash and a key count. backup-testisActiveandwebshows2/2.- The
etcd-datavolume points to/var/lib/etcd-restore.
Hints
Toon de hints
etcdctlneedsETCDCTL_API=3(default in new versions),--endpoints=https://127.0.0.1:2379,--cacert,--cert,--key.- In etcd 3.5+,
etcdutl snapshot restorereplacesetcdctl snapshot restore(the old one still works with a warning). - Change only the
hostPathof the volumeetcd-datainetcd.yaml; kubelet sees the change and restarts the pod (1–2 minutes). crictl ps | grep etcdshows the etcd container whilekubectldoes not work.
Oplossing
Toon de oplossing
- Read the paths.
grep -E "listen-client-urls|trusted-ca-file|cert-file|key-file" /etc/kubernetes/manifests/etcd.yamlTypical values: endpoint
https://127.0.0.1:2379, CA/etc/kubernetes/pki/etcd/ca.crt, cert/etc/kubernetes/pki/etcd/server.crt, key/etc/kubernetes/pki/etcd/server.key. - Snapshot and check it.
mkdir -p /opt/backup ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key snapshot save /opt/backup/etcd-$(date +%F).db etcdutl snapshot status /opt/backup/etcd-$(date +%F).db -w table - Break something.
kubectl delete ns backup-test - Restore into a new directory.
- Point etcd to it.
- Check the objects.
kubectl -n backup-test get deploy web NAME READY UP-TO-DATE AVAILABLE AGE web 2/2 2 2 12m - Certificates.
kubeadm certs check-expirationkubeadm certs renew allrenews them (then restart the control plane pods); a kubeadm upgrade also renews them. - Maintenance on a worker.
Mijn notities
Nog geen notities.