> ## 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.

# Role of etcd in Kubernetes

> Explains etcd as Kubernetes' durable distributed key value store for cluster state, its availability and backup best practices including clustering, off cluster snapshots, and secrets protection.

Kubernetes is stateful: it maintains the desired and current state of the cluster. Most control-plane components (API server, scheduler, controller-manager) are stateless — they do not persist cluster-wide state between restarts. The component that provides durable persistence for the entire cluster is etcd.

All cluster state lives in etcd.

etcd is a lightweight, distributed key-value store. Treat a key as a name (for example, the name of your app) and the value as the full description of that object (for example, which image to run and how many replicas you want).

![A dark-themed diagram illustrating etcd as a small key-value store, with the key "my-app" on the left and the value "run nginx — 5 copies" on the right.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Kubernetes/Role-of-etcd-in-Kubernetes/etcd-kv-myapp-run-nginx-5.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=c387cb6b7e2215ce1192793317120f5b)

A key might also hold sensitive data (for example, a database password). Note: [Kubernetes Secrets](https://kubernetes.io/docs/concepts/configuration/secret/) are stored in etcd (base64-encoded) by default. They are not encrypted at rest unless you enable [EncryptionConfiguration](https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/) or use an [external secrets store](https://external-secrets.io/). Protect etcd and snapshots accordingly.

When you run a declarative command like `kubectl apply` that specifies five replicas, the desired state is written into etcd via the API server:

```bash theme={null}
$ kubectl apply -f app.yaml
# Output (example)
deployment.apps/my-app created
```

app.yaml (minimal example):

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 5
  template:
    spec:
      containers:
      - name: nginx
        image: nginx:latest
```

Controllers, the scheduler, and kubelets continuously read the desired state (from the API server backed by etcd) and work to make the cluster converge to that state.

Teams sometimes assume that running multiple API servers alone makes the control plane highly available while overlooking etcd. If etcd is a single instance, it becomes a single point of failure — losing it prevents the cluster from knowing its desired state.

![A stylized diagram titled "Where Teams Get It Wrong" showing a Kubernetes control plane with three replicated API server icons across Node 1–3 on the left and a single etcd instance (shown split/broken) on the right. It illustrates the false sense of high availability when etcd is only a single copy.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/Kubernetes/Role-of-etcd-in-Kubernetes/single-etcd-single-point-of-failure.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=b0e7d0cf4bea6f569ecbcdb7d6a3d043)

To protect the cluster, follow these core best practices:

1. Run etcd as a small cluster (an odd number of members — typically 3 or 5). Raft consensus requires a quorum; with 3 members you can tolerate one failure, with 5 you can tolerate two.
2. Automate frequent, external snapshots of etcd and store them outside the cluster so they are available even if the cluster fails.

Quick reference — etcd protection options:

| Strategy | Purpose | Example / Notes |
| - | - | - |
| Run etcd as a cluster | Prevent single point of failure | Use 3 or 5 members (odd) to maintain quorum with Raft |
| Snapshot backups | Recover cluster state after catastrophic failure | `ETCDCTL_API=3 etcdctl snapshot save backup.db` and copy to object storage |
| Off-cluster storage | Ensure snapshots survive node/cluster loss | Store backups in S3, GCS, Azure Blob, or on a separate backup volume |
| Encrypt secrets at rest | Prevent readable secrets in etcd backups | Enable Kubernetes `EncryptionConfiguration` or use an external secrets store |

Example: create a local snapshot with etcdctl (etcd v3):

```bash theme={null}
# Set API version and save a local snapshot
$ export ETCDCTL_API=3
$ etcdctl --endpoints=https://127.0.0.1:2379 \
    --cacert=/path/ca.crt --cert=/path/client.crt --key=/path/client.key \
    snapshot save backup.db
```

Store snapshots off-cluster (for example, upload to object storage). Example using AWS CLI to copy to S3:

```bash theme={null}
$ aws s3 cp backup.db s3://my-etcd-backups/backup.db
```

Automate snapshot creation and upload (cron, systemd timers, or your backup system) and verify restores regularly.

Run etcd as a 3- or 5-member cluster (odd members for quorum) and automate frequent snapshots. With regular, off-cluster backups of etcd, you effectively back up your entire Kubernetes control plane state.

If you back up etcd, you have backed up your cluster state. Conversely, if you lose etcd and lack a recent snapshot, API server redundancy and node-level replication cannot restore the control-plane state — recovery becomes far more difficult and time-consuming.

Links and references

* [Kubernetes: Secrets concept](https://kubernetes.io/docs/concepts/configuration/secret/)
* [Kubernetes: Encrypting data at rest](https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/)
* [etcd: Snapshot and restore documentation](https://etcd.io/docs/latest/op-guide/snapshot/)
* [External Secrets Operator](https://external-secrets.io/)
* [AWS S3](https://aws.amazon.com/s3/)
* [Google Cloud Storage (GCS)](https://cloud.google.com/storage)
* [Azure Blob Storage](https://learn.microsoft.com/azure/storage/blobs/storage-blobs-introduction)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/devops-interview-prep/module/60905e58-3a8e-4423-9743-081b4959f0a0/lesson/0d424165-2427-4542-8959-21d03c8f2786)


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