Etcd is the backbone of your Kubernetes control plane, storing all cluster state and configuration data. Ensuring its security protects sensitive information and maintains cluster reliability. This guide covers: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.
- Encrypting data at rest
- Encrypting data in transit
- Backup and disaster recovery
1. Encrypting Data at Rest
By default, etcd writes plaintext data to disk. To safeguard sensitive objects—such as Secrets—enable Kubernetes’ built-in EncryptionConfiguration.Step 1. Create an EncryptionConfiguration
Save the following manifest asencryption-config.yaml:
| Field | Description |
|---|---|
| resources | List of resource types to encrypt (e.g., secrets, configmaps). |
| providers | Ordered providers: |
aescbcuses AES-CBC. Replace<base64-encoded-encryption-key>with a 32-byte Base64 key.identityleaves data unencrypted as a fallback. |
Run the following command to create a 32-byte random key:Copy the output into your
encryption-config.yaml.Step 2. Update the Etcd Static Pod
Modify/etc/kubernetes/manifests/etcd.yaml to include the provider config:
2. Encrypting Data in Transit
Protect etcd client-to-server and peer-to-peer communication with TLS certificates.Step 1. Provision Certificates
You need:- CA certificate (
ca.crt) - Server cert/key (
etcd-server.crt,etcd-server.key) - Peer cert/key (
etcd-peer.crt,etcd-peer.key) - Client cert/key (
etcd-client.crt,etcd-client.key)
Step 2. Configure TLS Flags
Extend your etcd manifest:| Flag | Purpose |
|---|---|
| —cert-file | Path to server TLS certificate for client connections |
| —key-file | Path to server TLS private key |
| —client-cert-auth | Require client certificates for authentication |
| —trusted-ca-file | CA certificate to verify clients |
| —peer-cert-file | TLS certificate for peer communication |
| —peer-key-file | TLS private key for peer communication |
| —peer-client-cert-auth | Require peer certificates for mutual TLS |
| —peer-trusted-ca-file | CA certificate to verify peer certificates |
Monitor your certificates’ expiration dates. Expired certificates break cluster communication and can cause downtime.
3. Backup and Disaster Recovery
Regular snapshots of etcd are essential for restoring cluster state in case of data loss or corruption.Taking a Snapshot
| Option | Description |
|---|---|
| ETCDCTL_API=3 | Use the v3 etcdctl API |
| snapshot save | Command to write snapshot to disk |
| —endpoints | Comma-separated list of etcd server URLs |
| —cacert, —cert, —key | TLS credentials for authenticating with etcd |
Summary
Securing etcd involves:- Encryption at Rest
UseEncryptionConfigurationto encrypt Secrets (and other resources) on disk. - Encryption in Transit
Enforce TLS for all client and peer connections. - Regular Backups
Automateetcdctl snapshotto maintain up-to-date backups.