متقدم
البحث فيالمعامل
طريقة البحث
  • ابحث عن مهمة أو أداة (lvm، selinux، ‎@podman)؛ وصفِّ حسب المستوى والكتاب أو الدورة.
  • مع مربع بحث فارغ، الفلتر وحده يعرض المعامل — مثلًا كل المعامل الصعبة لدورة واحدة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

معمل 3.1CKA, الفصل 3

Back up etcd, break the cluster, restore it

المستوى
صعب
45 دقيقة
الأجهزة
a kubeadm cluster (1 control plane node is enough), root on the control plane node
الحالة
لم يبدأ

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

الهدف

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.

قبل أن تبدأ

المهام

  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.

تحقّق من عملك

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.

تلميحات

اعرض التلميحات
  • 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.

الحل

اعرض الحل
  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

ملاحظاتي

لا توجد ملاحظات بعد.

دروس هذا المعمل

الأوامر في هذا المعمل