Creating a Secret Object
Begin by launching your Kubernetes playground—a single-node cluster running Kubernetes with ContainerD. Kubernetes makes it easy to create secrets from files, literal values, or environment files. Below are some example commands:--allow-missing-template-keys, --append-hash, and --dry-run can further refine your secret creation process.
After the command executes, verify the secret:
describe command provides detailed metadata, including the base64-encoded data:
Secret values are base64-encoded by default; they are not encrypted. Avoid pushing secret configuration files containing base64 values to public repositories.
Viewing the Encoded Secret
Kubernetes stores secret values in base64‑encoded format. Retrieve the secret as YAML to inspect its contents:Inspecting Secret Data in etcd
etcd is the key-value store where Kubernetes persists cluster data. Without encryption at rest, secret values remain only base64-encoded, allowing anyone with access to etcd to decode them. Use theetcdctl client (API version 3) to query etcd:
etcdctl client is installed. On Ubuntu, install it using:
Enabling Encryption at Rest
To protect sensitive data stored in etcd, Kubernetes offers an encryption at rest mechanism using an encryption provider configuration. First, verify if encryption is enabled by checking the kube-apiserver process:1. Create an Encryption Configuration File
Generate a random 32-byte key (base64-encoded) with:enc.yaml) with the following content (replace the sample key with your generated key):
2. Mount the Encryption Configuration File into the API Server
Next, incorporate the configuration into the kube-apiserver by performing these steps:-
Move the encryption configuration file to a secure directory:
-
Modify the kube-apiserver manifest (found at
/etc/kubernetes/manifests/kube-apiserver.yaml) by adding the--encryption-provider-configflag. Include a new volume and volume mount for the/etc/kubernetes/encdirectory. For example:
Verifying Encryption
Once encryption is activated, any new secret you create will be encrypted at rest. Create a new secret:Always update your existing secrets after enabling encryption at rest to ensure full protection of sensitive data.
Conclusion
This guide demonstrated how Kubernetes handles secret data by showing that, by default, secrets are only base64-encoded—not encrypted—in etcd. We then detailed the process for enabling encryption at rest: creating an encryption configuration file, mounting it into the API server, and verifying that new secrets store their data securely. By following these steps, you can significantly enhance the security posture of your Kubernetes cluster. Happy encrypting!Additional Resources
For further reading on securing your Kubernetes environment, consider consulting the Kubernetes Documentation.