Geavanceerd
Zoeken inLabs
Zo zoek je
  • Zoek een taak of een tool (lvm, selinux, @podman); filter op niveau en op boek of cursus.
  • Met een leeg zoekvak toont een filter alleen al de labs — bijvoorbeeld alle moeilijke labs van één cursus.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Lab 3.1CKA, Hoofdstuk 3

Back up etcd, break the cluster, restore it

Niveau
Moeilijk
45 min
Machines
a kubeadm cluster (1 control plane node is enough), root on the control plane node
Status
Nog niet begonnen

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

Taken

  1. Find the etcd endpoint and the paths of the CA, server certificate and key in /etc/kubernetes/manifests/etcd.yaml.
  2. Save a snapshot to /opt/backup/etcd-$(date +%F).db and check its status (hash, revision, number of keys).
  3. Delete the namespace backup-test.
  4. Restore the snapshot into /var/lib/etcd-restore.
  5. Change the etcd static pod to use the new data directory. Wait until the API server works again.
  6. Check that backup-test and the deployment web are back.
  7. Show when the cluster certificates expire.
  8. 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 status showed a hash and a key count.
  • backup-test is Active and web shows 2/2.
  • The etcd-data volume points to /var/lib/etcd-restore.

Hints

Toon de hints
  • etcdctl needs ETCDCTL_API=3 (default in new versions), --endpoints=https://127.0.0.1:2379, --cacert, --cert, --key.
  • In etcd 3.5+, etcdutl snapshot restore replaces etcdctl snapshot restore (the old one still works with a warning).
  • Change only the hostPath of the volume etcd-data in etcd.yaml; kubelet sees the change and restarts the pod (1–2 minutes).
  • crictl ps | grep etcd shows the etcd container while kubectl does not work.

Oplossing

Toon de oplossing
  1. Read the paths.
    grep -E "listen-client-urls|trusted-ca-file|cert-file|key-file" /etc/kubernetes/manifests/etcd.yaml

    Typical 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.

  2. 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
  3. Break something.
    kubectl delete ns backup-test
  4. Restore into a new directory.
    etcdutl snapshot restore /opt/backup/etcd-$(date +%F).db --data-dir /var/lib/etcd-restore
  5. Point etcd to it.
    sed -i 's#path: /var/lib/etcd$#path: /var/lib/etcd-restore#' /etc/kubernetes/manifests/etcd.yaml
    watch crictl ps
    kubectl get nodes
  6. Check the objects.
    kubectl -n backup-test get deploy web
    NAME   READY   UP-TO-DATE   AVAILABLE   AGE
    web    2/2     2            2           12m
  7. Certificates.
    kubeadm certs check-expiration

    kubeadm certs renew all renews them (then restart the control plane pods); a kubeadm upgrade also renews them.

  8. Maintenance on a worker.
    kubectl drain worker1 --ignore-daemonsets --delete-emptydir-data
    kubectl get nodes
    kubectl uncordon worker1

Mijn notities

Nog geen notities.

Lessen voor dit lab

Commando's in dit lab