Kubernetes Configuration
Decouple configuration artifacts from image content to keep containerized applications portable.1. ConfigMaps
Used to store non-confidential data in key-value pairs.- Environment variables
- Command-line arguments
- Configuration files
Creating ConfigMaps
Imperative (CLI):Using ConfigMaps in Pods
As Environment Variables:2. Secrets
Used to store sensitive information, such as passwords, OAuth tokens, and SSH keys.- Stored in
etcd(encrypted at rest if configured). - Mounted into pods as files or environment variables.
- Base64 encoded (not encrypted by default in YAML!).
Creating Secrets
Imperative:Using Secrets in Pods
As Environment Variables:Best Practices
Don't Commit Secrets to Git
Don't Commit Secrets to Git
Never commit YAML files containing Base64 encoded secrets. Use tools like Sealed Secrets, External Secrets Operator, or Vault.
Immutable ConfigMaps
Immutable ConfigMaps
Set
immutable: true for ConfigMaps/Secrets to prevent accidental updates and improve performance.Hot Reloading
Hot Reloading
If you mount a ConfigMap as a volume, updates propagate to the file automatically (eventually). Apps need to watch the file for changes to reload without restart.
Resource Quotas
Limit resource consumption per namespace.LimitRanges
Set default and max/min resource constraints for pods/containers in a namespace.Priority Classes
Control pod scheduling and eviction priority.| Built-in Priority | Value | Use Case |
|---|---|---|
system-cluster-critical | 2000000000 | kube-system pods |
system-node-critical | 2000001000 | Node-critical pods |
| Custom high priority | 1000000 | Production apps |
| Default (none set) | 0 | Standard workloads |
Secrets Management Best Practices
1. External Secrets Operator
Sync secrets from external sources (AWS Secrets Manager, HashiCorp Vault).2. Sealed Secrets
Encrypt secrets that can be safely stored in Git.3. Enable etcd Encryption
Encrypt secrets at rest in etcd:Interview Questions & Answers
What is the difference between ConfigMaps and Secrets?
What is the difference between ConfigMaps and Secrets?
| Aspect | ConfigMap | Secret |
|---|---|---|
| Purpose | Non-sensitive config | Sensitive data |
| Encoding | Plain text | Base64 encoded |
| At-rest encryption | No | Optional (etcd encryption) |
| Size limit | 1MB | 1MB |
| Mounting | Env vars or volumes | Env vars or volumes |
Are Kubernetes Secrets actually secure?
Are Kubernetes Secrets actually secure?
Not by default!
- Secrets are only Base64 encoded, not encrypted
- Anyone with RBAC access can read them
- They’re stored in etcd (unencrypted by default)
- Enable etcd encryption at rest
- Use RBAC to restrict access
- Use external secret management (Vault, AWS Secrets Manager)
- Use Sealed Secrets for GitOps
How do you update a ConfigMap without restarting pods?
How do you update a ConfigMap without restarting pods?
Option 1: Volume mount - ConfigMap changes propagate automatically (with delay)Option 3: Use Reloader - Automatically restarts pods when ConfigMap changes:
- App must watch file for changes
What is the purpose of ResourceQuotas?
What is the purpose of ResourceQuotas?
ResourceQuotas prevent resource exhaustion in multi-tenant clusters by:
- Limiting total CPU/memory per namespace
- Limiting number of objects (pods, services, secrets)
- Enforcing resource requests/limits on all pods
How do you handle secrets rotation?
How do you handle secrets rotation?
- External Secrets Operator: Auto-syncs from external sources on schedule
- Volume-mounted secrets: Kubernetes updates files (apps must reload)
- Rolling restart:
kubectl rollout restartto pick up new secrets - Sidecar pattern: Use a sidecar that watches for secret changes
Common Pitfalls
Key Takeaways
- Use ConfigMaps for plain text config.
- Use Secrets for sensitive data.
- Inject as Environment Variables for simple values.
- Mount as Volumes for config files.
- Base64 is NOT encryption!
- Use ResourceQuotas and LimitRanges for multi-tenant clusters.
- Implement proper secrets management with external tools.
Next: Kubernetes Storage →