Never store plaintext passwords in your code or in a
ConfigMap. Use Kubernetes Secrets for all sensitive data.1. Creating Secrets
Secrets can be created imperatively withkubectl or declaratively with a YAML manifest.
1.1 Imperative Creation
Specify key-value pairs on the command line:key=value per line):
1.2 Declarative Creation
Define aSecret manifest in secret-data.yaml:
You can decode any value with
echo '<base64>' | base64 --decode. Keep your raw files out of version control.2. Viewing Secrets
List all existing secrets:3. Injecting Secrets into Pods
You can consume Secrets as environment variables or as mounted volumes.3.1 All Keys as Environment Variables
Add anenvFrom directive to your Pod spec:
3.2 Single Key as an Environment Variable
UsevalueFrom.secretKeyRef for a specific key:
3.3 Mounting Secrets as Files
Mount the secret into a volume:Try the exercises to practice creating, viewing, and injecting Secrets in your Kubernetes clusters!