Kubernetes ConfigMap and Secret Management
Create and use ConfigMaps and Secrets for application configuration with env vars and volume mounts.
# ConfigMap for non-sensitive configuration
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
namespace: production
data:
APP_ENV: production
LOG_LEVEL: info
MAX_CONNECTIONS: '100'
config.json: |
{
"features": {
"darkMode": true,
"betaAccess": false
}
}
---
# Secret for sensitive data (base64 encoded)
apiVersion: v1
kind: Secret
metadata:
name: app-secrets
namespace: production
type: Opaque
data:
DB_PASSWORD: cGFzc3dvcmQxMjM=
API_KEY: c2stbGl2ZS1hYmMxMjM=
stringData:
JWT_SECRET: my-super-secret-jwt-key
---
# Pod using both ConfigMap and Secret
apiVersion: v1
kind: Pod
metadata:
name: api-pod
spec:
containers:
- name: api
image: api-server:latest
envFrom:
- configMapRef:
name: app-config
- secretRef:
name: app-secrets
volumeMounts:
- name: config-volume
mountPath: /app/config
readOnly: true
volumes:
- name: config-volume
configMap:
name: app-config
items:
- key: config.json
path: config.jsonSponsored
DigitalOcean
Use Cases
- Managing application configuration in Kubernetes
- Injecting secrets without hardcoding
- Mounting configuration files into containers
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Kubernetes ConfigMap and Secrets
Create and use Kubernetes ConfigMaps and Secrets for application configuration management.
Best for: Externalizing application configuration in K8s
Kubernetes Deployment Manifest
Production-ready Kubernetes deployment with resource limits, probes, rolling updates, and anti-affinity.
Best for: Deploying containerized applications to Kubernetes
Kubernetes HPA — Horizontal Pod Autoscaler
Configure horizontal pod autoscaling based on CPU, memory, and custom metrics for Kubernetes workloads.
Best for: Auto-scaling APIs based on traffic load
Kubectl Rollout — Restart, Status, and Undo
Essential kubectl rollout commands for deployments: restart, status checks, history, and rollback.
Best for: Zero-downtime deployment restarts