Appearance

Backup, restore, and disaster recovery

Recover Kubernetes API state in an isolated environment and verify what the recovered cluster can and cannot supply.

What you will understand

  • Inventory which state belongs in an etcd snapshot and which needs its own backup.
  • Explain how restored membership and revision handling affect Kubernetes clients.
  • Verify a recovery point against known records before reconnecting workflows.

Builds on: Termination, disruption, and drain, PKI, kubeadm, and safe upgrades

Choose what to back up separately

A cluster is lost after a storage failure. You need to recover Deployment and Service definitions, the credentials saved through the API, and the files written by a stateful workload. An etcd snapshot captures persisted Kubernetes API records at a point in time. It can restore a PVC object and information about a workload. The volume bytes are in a separate storage system and need their own backup. Include network and cloud resources, cluster configuration, and keys needed to decrypt encrypted API data in the recovery inventory.

In the scene, classify what can be recovered from the API snapshot and what must come from another source. Decide how much recent data you can afford to lose and how long a recovery can take, then choose how often to capture each source.

Where do you back up API records and data files?

An etcd snapshot covers objects stored by the API. Volume bytes and external dependencies need additional recovery sources.

  1. Capture the API-state snapshot

    An etcd snapshot contains stored API objects and may contain sensitive Secret data.

  2. Locate the application data bytes

    A PVC object is not its volume contents; application files and external stores need their own backup path.

  3. Assemble the independent recovery assets

    Trust, signing and encryption material plus compatible infrastructure and application backups complete the plan.

The exact asset list depends on cluster encryption, providers and application dependencies.

Explore another case

Restore an isolated etcd cluster

An etcd snapshot restore builds new member data directories. It needs deliberate cluster membership and separation from the original members. A snapshot may also be behind the revisions Kubernetes watchers have already seen. Upstream etcd guidance for Kubernetes recommends a revision bump and marking history compacted so clients with stale watches are forced to relist. Review the procedure for your etcd version and rehearse on a separate target.

What makes a restored control plane safe to inspect?

Restore into isolated membership, then verify API objects and client watches before allowing controllers to reach external systems.

  1. Isolate the recovery target

    The rehearsal uses a separate cluster and stops its API server and etcd before replacing target state.

  2. Restore the snapshot with explicit membership

    Compatible tools restore into a new directory with the planned membership, revision bump and compaction marking.

  3. Verify the state and rebuild observers

    The API returns backed-up objects; stale controller watches must rebuild rather than assume old history remains valid.

The local script performs a single-member API-data rehearsal, not production membership recovery or worker migration.

Explore another case

Verify the restored objects

The disposable lab creates a known ConfigMap before taking its backup. From the downloaded module directory, the script writes recovery material to a private host directory. Inspect the runbook before starting the optional offline restore. Use the separate recovery kubeconfig to verify the marker in kv-recovery, compare its value to the captured state, and discard only the isolated cluster when finished.

apiVersion: v1
kind: ConfigMap
metadata:
  name: m18
  namespace: kv-lab
  labels:
    lab: m18
data:
  marker: captured-before-disaster
# In the downloaded m18 directory: captures to a private host directory.
bash run.sh
backup_dir=$(python3 backup-path.py m18)
# Inspect RECOVERY.md and restore-offline.sh before this optional step.
bash restore-offline.sh
# Use the separate file produced by the recovery script, never your active context.
KUBECONFIG="$backup_dir/recovery.kubeconfig" kubectl -n kv-lab get configmap m18 -o yaml
# Discard only the isolated rehearsal target after inspection.
KUBECONFIG="$backup_dir/recovery.kubeconfig" kind delete cluster --name kv-recovery

The backup and recovery lab demonstrates a single-member snapshot restore. That lets you verify API state and the separation of targets. A production plan must also test restored certificates, decryption, adequate etcd membership, storage reattachment or data recovery, and application health with real dependencies.

Keep restored controllers away from live systems

Restored controllers can act on old intent. They might see a Job ready to run or a cloud resource that the primary environment still manages. Isolate credentials and external connections while verifying the restored API. Check backup age and integrity, compare expected object records, and verify application data separately.

Check your understanding

The recovery cluster shows the PVC and original Deployment. Is that enough to reopen the stateful service?

Those objects confirm portions of the saved API state. Verify that the correct storage is attached or restored, check the expected application records, and confirm clients can reach a healthy instance before resuming normal traffic.

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu