> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Disaster Recovery in Kubernetes

> Guide for preparing Kubernetes disaster recovery by backing up configuration and persistent data, restoring clusters and PVs, defining RPO and RTO, and testing repeatable recovery procedures.

How should you prepare for disaster recovery in Kubernetes?

This guide walks through a practical scenario, the exact backups you need, and a repeatable recovery flow so your application can be restored if a Kubernetes cluster is lost.

## Scenario

* Your order-processing application is running in Kubernetes and serving customers.
* Pods are healthy, the Service receives traffic, and customer orders are stored in a database.
* Suddenly the Kubernetes cluster becomes unavailable — the control plane is down, the infrastructure failed, or the cluster was accidentally deleted.
* You need to get the application running in a recovery environment and restore the data so customers can continue placing and retrieving orders.

## What Kubernetes manifests give you — and what they don’t

Kubernetes manifests (Deployments, Services, PersistentVolumeClaims, StatefulSets, Helm charts, CRDs, etc.) describe the desired cluster configuration. If you create a new cluster and apply those manifests, Kubernetes will recreate the objects and begin starting pods and services:

```bash theme={null}
# manifests/
deployment.yaml
service.yaml
postgres.yaml

# apply manifests
kubectl apply -f manifests/
```

Important distinctions:

* Manifests recreate configuration and workload definitions (Deployments, Services, RBAC, ConfigMaps, Secrets).
* Manifests may recreate PVC objects, but they do not automatically recreate the underlying Persistent Volume (PV) data. The cloud disk, CSI-backed volume, or snapshot must be restored separately.
* If you restore manifests without restoring data, PVCs will be empty or remain unbound and stateful applications will start with no customer data.

Key action: treat configuration and persistent application data as separate recovery items.

Store configuration and data backups in environments independent of the protected cluster (for example, cross-region object storage or a different datacenter). This ensures backups survive cluster-level failures.

## Two types of backups (what to back up)

You need both configuration backups and application data backups. The table below summarizes the purpose and examples for each.

| Backup type | What it covers | Examples / Tools |
| - | - | - |
| Configuration backup | Kubernetes resource definitions required to run your app: YAML manifests, Helm charts, CRDs, ClusterRoles, Namespaces, RBAC. | Git repositories, Helm chart repositories, `kubectl get --export`, ArgoCD/GitOps, Velero resource backup |
| Data backup | Persistent application state and customer data: DB dumps, PV snapshots, continuous replication. | Database dumps (`pg_dump`), PV snapshots (CSI snapshots), Velero + restic, managed DB replicas, logical replication |

Recommended tools:

* Velero — backup of cluster resources and PV snapshots for many clouds.
* Cloud provider snapshot tools (AWS EBS snapshots, GCP persistent disk snapshots, Azure disk snapshots).
* Database-native backups: `pg_dump`, logical replication, point-in-time recovery (PITR).

## Recovery flow (step-by-step)

1. Create a new Kubernetes cluster or bring up an alternate environment.
2. Prepare the recovery cluster:
   * Install required cluster-scoped resources (CRDs, ClusterRoles, StorageClasses).
   * Install CSI drivers and storage integrations that the original cluster used so PVs can be restored and bound.
3. Restore configuration:
   * Apply your manifests or install Helm charts to recreate Namespaces, Deployments, Services, RBAC, etc.
   * Restore cluster-level resources such as CRDs and ClusterRoles before applying application manifests.
4. Restore application data:
   * Restore database from backups (logical dump restore, PV snapshot restore, or promote a replica).
   * Make sure PVCs bind to restored PVs or that StatefulSet volumes map to the restored storage.
5. Verify the application:
   * Start the application and run end-to-end tests (place/read orders) to validate correctness.
   * Check logs, readiness/liveness probes, and monitoring/alerting for errors.

Example: using Velero to restore both resources and PV snapshots

* Install Velero in the recovery cluster and configure it to access your off-cluster object storage and snapshot provider.
* Use Velero restore commands to bring back resources and PV snapshots.

## Recovery metrics: RPO and RTO

* Recovery Point Objective (RPO) — how much data you can afford to lose.
  * Example: RPO = 15 minutes means backups or replication must capture changes at least every 15 minutes.
* Recovery Time Objective (RTO) — how quickly the application must be back online.
  * Example: RTO = 1 hour means the entire recovery process (cluster creation, restore, validation) must complete within 1 hour.

These metrics drive choices for backup frequency, replication vs. snapshots, automation level, and runbook complexity.

## Test your restores

Backups are only useful if they can be restored. Test restores regularly to a non-production recovery environment:

* Provision a recovery cluster or dedicated recovery namespace.
* Restore configuration and data into that environment.
* Deploy the application and simulate user traffic: place orders, query orders, validate state transitions.
* Time the entire process and verify you meet the RTO.
* Update runbooks based on lessons learned.

Don’t assume backups are valid without testing. A regularly tested restore process and a documented runbook are essential — when production is down you want a practiced process, not surprises.

## Operational recommendations (checklist)

* Keep manifests, Helm charts, and cluster-level configuration in version control (Git).
* Store data backups off-cluster in durable, geographically separate object storage.
* Define RPO and RTO for each application and implement a backup cadence that meets the RPO.
* Automate backups: scheduled DB dumps, scheduled PV snapshots, or continuous replication.
* Encrypt backups at rest and in transit and manage keys securely (KMS).
* Maintain a tested runbook for recovery steps and update it after every test.
* Periodically perform full restore drills and validate application behavior, performance, and data integrity.
* Use managed backup/DR tools where appropriate (Velero, cloud provider snapshot services, or commercial DR solutions).
* Monitor backup jobs and set alerts for failed or delayed backups.

Quick checklist table:

| Task | Frequency |
| - | - |
| Backup application configuration to Git | Continuous / on change |
| Full DB backup (logical) | Daily or per RPO |
| Incremental backups or WAL shipping | As required for RPO (e.g., every 5–15 minutes) |
| PV snapshots | As required, and before critical upgrades |
| Restore drills | Quarterly or as required by policy |
| Runbook review | After each drill or significant change |

## Example commands and patterns

* Apply manifests:

```bash theme={null}
kubectl apply -f manifests/
```

* Export cluster resources to YAML for backup:

```bash theme={null}
kubectl get deploy,svc,configmap,secret -o yaml --namespace my-app > my-app-resources.yaml
```

* Database logical dump (Postgres example):

```bash theme={null}
pg_dump -U postgres -h db-host -Fc orders_db > orders_db.dump
# restore
pg_restore -U postgres -d orders_db orders_db.dump
```

* Velero backup and restore (high level):

```bash theme={null}
# backup
velero backup create my-app-backup --include-namespaces my-app

# restore
velero restore create --from-backup my-app-backup
```

Note: the exact PV snapshot/restore sequence depends on your CSI driver and cloud provider. Confirm StorageClass and CSI snapshot class exist in the recovery cluster.

## Summary

* Kubernetes manifests let you recreate configuration and workloads, but they don’t recreate persistent application data by themselves.
* Implement two complementary backup strategies: configuration backups (YAML, Helm, CRDs) and data backups (DB dumps, PV snapshots, replication).
* Store backups off-cluster in a durable, separate environment.
* Define RPO and RTO to shape backup frequency and recovery automation.
* Regularly test restores, maintain runbooks, and automate as much of the recovery flow as possible to reduce manual errors and meet recovery objectives.

## Links and references

* [Kubernetes Documentation](https://kubernetes.io/docs/)
* [Velero — Backup and Restore for Kubernetes](https://velero.io/)
* [Kubernetes Persistent Volumes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/)
* Cloud provider snapshot docs: AWS EBS snapshots, GCP Persistent Disk snapshots, Azure Disk snapshots

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/devops-interview-prep/module/60905e58-3a8e-4423-9743-081b4959f0a0/lesson/ffa96b68-2bd2-4f98-9632-587e72061464)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.