0%
Kubernetes CKA and CKAD Exam Prep: Hands On Task Drills and Mock Exams
How the Exams Work
Application Developer (CKAD) Skills
Mock Exams
etcd Backup and Restore
Backing up and restoring etcd is one of the few administrator exam tasks that appears in nearly every version of the exam guide, and one of the few where a single typo can quietly cost you the whole task. It is not hard. It is a sequence of four or five commands with long flags, followed by a manifest edit and a wait. This lesson builds the picture you need to do it without hesitating: what etcd stores, where its files and certificates live on a kubeadm node, how to take a snapshot, how to restore it into a fresh directory, how to point the cluster at it, and how to prove it worked.
The previous lesson covered static pods and the control plane layout, so this one assumes you know that etcd runs as a static pod from /etc/kubernetes/manifests/etcd.yaml. Troubleshooting a broken control plane in general belongs to the troubleshooting lesson; here the focus is on etcd data.
etcd is the cluster's memory
etcd is a distributed key value store. Kubernetes keeps every API object in it: Deployments, Pods, Services, Secrets, ConfigMaps, RBAC rules, CustomResourceDefinitions and their custom resources, leases, events and more. Each object lives under a key such as /registry/deployments/default/web, and its value is the serialised object, by default in protobuf form. Each write increments a global revision number, which is how watches and resourceVersion work.
Only the API server talks to etcd. Controllers, the scheduler, kubelets and kubectl all go through the API server, which validates, authorises and admits requests before storing them. That design has a useful consequence for backups: a snapshot of etcd is a snapshot of the whole cluster's desired and observed state. Restore it and the API server serves exactly what existed at that revision. Kubelets then reconcile the running containers to match.
What etcd does not hold is just as important. It does not hold container images, the contents of persistent volumes, logs, or anything on node disks. A restored cluster has the PersistentVolumeClaim objects from the snapshot, but the data in the volumes is whatever the storage system holds now. Application data needs its own backup strategy.
Raft, members and quorum
etcd replicates its data across members using the Raft consensus protocol. One member is the leader and all writes go through it; a write is committed once a majority of members have stored it. That majority is the quorum. With three members the cluster tolerates one failure; with five it tolerates two. With one member, which is what most exam clusters use, there is no fault tolerance at all, and the single etcd is a single point of failure for the cluster.
Quorum matters for restores. A snapshot restore creates a new cluster with new membership metadata. In a multi member etcd, you restore the same snapshot on every member with matching membership flags and start them all together. In the single member case, which is what the exam normally sets, the restore is simpler, but the membership flags still exist and are worth understanding.
Stacked and external topologies
kubeadm supports two layouts. In the stacked topology, the default, each control plane node runs its own etcd member as a static pod next to the API server, and the API server talks to the local member at https://127.0.0.1:2379. In the external topology, etcd runs on separate machines, usually as a systemd service, and the API server's --etcd-servers flag lists their addresses.
You can tell which one you have in seconds:
If there is no etcd.yaml on the control plane and --etcd-servers points elsewhere, the task is about an external etcd, and the restore ends with editing a systemd unit or its environment file instead of a static pod manifest. The commands for snapshot and restore are the same in both cases.
Reading the etcd manifest
The etcd static pod manifest contains every value you need for a backup. Open it before every etcd task and read the command section.
Further down, the volumes section mounts two hostPath directories: etcd-certs from /etc/kubernetes/pki/etcd and etcd-data from /var/lib/etcd. The data directory flag and the etcd-data volume are the two lines that matter for a restore.
Why the exam keeps asking for this
From an operator's point of view, an etcd backup is the minimum disaster recovery plan for a self managed cluster. A bad upgrade, a deleted namespace, a corrupted disk or an operator mistake with a script can all be undone with a recent snapshot. Managed services such as the big cloud providers' Kubernetes offerings run and back up etcd for you, which is why many engineers have never touched it. The administrator exam targets people who run their own control planes, so it checks that you can do it correctly under pressure.
The task usually reads like this: take a snapshot of the etcd instance at a given endpoint and save it to a given path, then restore an existing snapshot from another path. The grader checks that the snapshot file exists and is valid, and that the cluster afterwards serves the state from the restored snapshot. Both halves are independent, so a mistake in the restore does not cost you the backup points.
Tools: etcdctl and etcdutl
Two command line tools ship with etcd. etcdctl is the network client: it connects to a running etcd over TLS and performs reads, writes, member operations and snapshot save. etcdutl is the offline utility: it works directly on data files and is the tool for snapshot restore and snapshot status. Older guides use etcdctl snapshot restore, which still works on etcd 3.5 with a deprecation warning but has been removed from the newest etcdctl releases. Use etcdutl for restore and status whenever it is installed, and fall back to etcdctl only if the node does not have etcdutl.
On etcdctl 3.4 and later the v3 API is the default, so the old ETCDCTL_API=3 prefix is no longer required. It does no harm, and you will see it in older documentation and in many exam environments' examples.
Looking inside etcd safely
It helps to see the keys once, so the idea of "every object is a key" becomes concrete. With the connection flags from the manifest, you can list keys without values. Do this on a practice cluster, not on an exam cluster where a careless put or delete could break the task.
You will see the resource type and namespace in each key. Values are protobuf encoded and not pleasant to read, which is fine: you never edit them directly. The only supported way to change cluster state is the API server, because it enforces validation, admission and RBAC that a raw etcd write would bypass. Treat direct etcd access as read only, for backups and diagnosis.
Size, revisions and why snapshots stay small
etcd keeps a history of revisions so that watches can resume, and the API server asks it to compact old revisions every few minutes. A snapshot contains the current keyspace plus whatever history has not been compacted yet, which is why a small cluster's snapshot is only a few megabytes. A busy cluster with many large objects, for example thousands of ConfigMaps or big CustomResources, can reach hundreds of megabytes. Size matters because snapshot save streams the whole database over the client connection, and restore writes it back to disk; both take longer and need more free space as the database grows. On the exam, expect small files and fast commands. If a save takes more than a few seconds on an exam cluster, suspect a connection problem rather than size.
What the grader sees
It is worth picturing the check script, because it tells you what to be careful about. For the backup half, a script can only look at the file: does it exist at the exact path, and does etcdutl snapshot status accept it. For the restore half, it asks the API server whether specific objects exist. Nothing checks how elegant your commands were. Exact paths and the final cluster state are everything, which is why the drills in this lesson always end with an ls of the file and a kubectl check of an object.
Restoring etcd brings back every Kubernetes object at the snapshot's revision, including Secrets and RBAC. It does not bring back files inside persistent volumes, container images or logs.