الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

etcdctl

The client for etcd, the key-value store that holds the whole state of a Kubernetes cluster — backup and restore are CKA tasks.

المستوى
خدمة DevSecOps
المجموعة
قواعد البيانات والرسائل
يحتاج root
نعم
الحزمة
etcd
يُسمّى أيضًا
etcd, etcdutl

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

ماذا يفعل

etcd is a distributed key-value store (Raft consensus) on port 2379 (clients) and 2380 (peers). Kubernetes keeps every object (pods, secrets, config) in it. If etcd is lost without a backup, the cluster is lost. etcdctl (API v3) reads keys, checks health and makes snapshots; etcdutl restores snapshots and checks them offline.

On kubeadm clusters etcd runs as a static pod and needs the client certificates in /etc/kubernetes/pki/etcd/.

طريقة الكتابة

ETCDCTL_API=3 etcdctl --endpoints=URL --cacert=CA --cert=CRT --key=KEY COMMAND
etcdutl snapshot restore FILE --data-dir DIR

الأجزاء الرئيسية

Commands

endpoint health / endpoint status
Is etcd healthy? Who is leader?
member list
Cluster members.
snapshot save FILE
Make a backup.
snapshot status FILE (etcdutl)
Check a backup.
snapshot restore FILE (etcdutl)
Restore into a new data folder.
get KEY [--prefix --keys-only]
Read keys.
put KEY VALUE / del KEY
Write / delete (never on a Kubernetes etcd by hand).
defrag
Free space after compaction.
alarm list / alarm disarm
Space alarms.

الخيارات 5

الأكثر استخدامًا

Flags

--endpoints=https://127.0.0.1:2379
Server(s).
--cacert / --cert / --key
TLS files.
-w table|json
Output format.
--data-dir DIR
Target folder (restore).
--prefix --keys-only
List keys under a path.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Set the TLS flags once (kubeadm)

    export ETCDCTL_API=3
    export ETCDCTL_ENDPOINTS=https://127.0.0.1:2379 ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt ETCDCTL_CERT=/etc/kubernetes/pki/etcd/server.crt ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key
  2. 2Health and members

    etcdctl endpoint health
    etcdctl endpoint status -w table
    etcdctl member list -w table
  3. 3Back up (CKA)

    etcdctl snapshot save /opt/backup/etcd-$(date +%F).db
    etcdutl snapshot status /opt/backup/etcd-2026-10-27.db -w table
  4. 4Find the cert paths from the static pod

    grep -E "cert-file|key-file|trusted-ca-file|listen-client-urls" /etc/kubernetes/manifests/etcd.yaml
  5. 5Restore (CKA)

    etcdutl snapshot restore /opt/backup/etcd-2026-10-27.db --data-dir /var/lib/etcd-restore
    vim /etc/kubernetes/manifests/etcd.yaml
        - hostPath: { path: /var/lib/etcd-restore, type: DirectoryOrCreate }
    crictl ps | grep etcd
    kubectl get pods -A
  6. 6See how Kubernetes stores objects

    etcdctl get /registry/namespaces --prefix --keys-only | head
  7. 7Check that Secrets are encrypted at rest

    etcdctl get /registry/secrets/shop/db | hexdump -C | head -3

    You should see k8s:enc:aescbc:v1: or k8s:enc:kms, not clear text.

  8. 8Fix a full database (NOSPACE alarm)

    etcdctl alarm list
    etcdctl defrag
    etcdctl alarm disarm
  9. 9Back up every night with a timer

    cat /usr/local/bin/etcd-backup.sh
    #!/bin/bash
    etcdctl snapshot save /opt/backup/etcd-$(date +%F).db && find /opt/backup -name 'etcd-*.db' -mtime +7 -delete
  10. 10k3s with embedded etcd

    k3s etcd-snapshot save --name manual

انتبه

  • An etcd snapshot contains all Secrets — encrypt it and store it off the node.
  • Never write keys by hand in a Kubernetes etcd.
  • Restore on all control-plane nodes the same way, or the cluster splits.

الملفات

/var/lib/etcd/
Data folder (kubeadm).
/etc/kubernetes/manifests/etcd.yaml
Static pod (kubeadm).
/etc/kubernetes/pki/etcd/
Certificates.

نصائح للحفظ

  • CKA: read the paths from etcd.yaml, do not guess them; etcdctl snapshot save must use the right certs.

رموز الخروج

0Success.
1Error.