Sub topic 1
What a Kubernetes backup must cover
A Kubernetes backup has to protect two different things: the cluster's state and your applications' data. Losing either one means a failed recovery. This chapter explains the difference and tells you which tool the rest of the tutorial uses for each.
Prerequisites
This chapter assumes you have:
- Basic kubectl usage and familiarity with Pods, Deployments, and PersistentVolumeClaims (PVCs).
- Comfort with the Linux command line and SSH access to a node.
- Awareness that the control plane stores cluster state in etcd.
- Basic knowledge of S3-compatible object storage.
Two kinds of things to protect
Cluster state is the set of API objects the cluster knows about. It includes Deployments, Services, ConfigMaps, Secrets, RBAC rules, and custom resources. The API server keeps all of it in etcd, a key-value store on the control plane.
Application data is what your workloads write at runtime. A database's table files, uploaded images, and a message queue's log segments are all application data. It lives in persistent volumes, not in etcd. etcd only stores the PersistentVolumeClaim and PersistentVolume objects that point at the storage.
Each kind of loss needs its own backup:
| Lost item | Where it lives | What restores it |
|---|---|---|
| Deployment, Service, ConfigMap, Secret | etcd | etcd snapshot, or a Velero backup of the objects |
| Contents of a database volume | Persistent volume | Volume snapshot or file-level copy of the volume |
| PVC object that names the volume | etcd | etcd snapshot or Velero |
If you restore only etcd, the PVC objects come back but the volume contents may not. If you copy only the volumes, you still have to recreate every Deployment and Secret by hand.
The tools in this tutorial
- etcd snapshots capture the whole cluster state at one moment. You take them on a control plane node with
etcdctl. They are the right tool for rebuilding a broken control plane, but they do not contain volume data. - Velero talks to the Kubernetes API. It saves selected resources to object storage and can also back up volume data. It works on a namespace, a label selector, or a resource type, so you can restore a single application.
The later chapters cover each tool in detail. For now, remember that the two tools overlap on cluster state and differ on scope and volumes.
Inventory what you must cover
Before choosing a tool, list what holds state in your cluster. This command shows every PVC and the storage class behind it:
kubectl get pvc --all-namespaces \
-o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,STORAGECLASS:.spec.storageClassName,VOLUME:.spec.volumeNameAny namespace in the output holds application data that needs a volume-level backup. Namespaces with no PVCs, such as stateless web front ends, can be rebuilt from their resource definitions alone.
Common gaps
- Backing up etcd and assuming volumes are included. They are not.
- Storing backups on the same node or storage system as the source. A node or storage failure then destroys both.
- Never restoring. A backup you have not restored is an untested assumption. The final chapter covers restore tests.
- Forgetting external dependencies. DNS records, load balancers, and cloud databases live outside the cluster and need their own recovery plan.
Exercise
A cluster loses its control plane and you restore an etcd snapshot taken that morning. The PVC objects reappear, but the database's volume is empty because the underlying disk was also lost. Which part of the backup plan was missing?
Show answer
A backup of application data. etcd snapshots hold only cluster state, such as the PVC and PV objects, not the contents of the volumes. You need a volume snapshot or file-level volume backup, for example through Velero, taken alongside the etcd snapshot.