bashintermediate
Kubernetes ConfigMap and Secrets
Create and use Kubernetes ConfigMaps and Secrets for application configuration management.
bashPress ⌘/Ctrl + Shift + C to copy
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_ENV: production
LOG_LEVEL: info
MAX_CONNECTIONS: "100"
config.json: |
{
"feature_flags": {
"new_ui": true,
"beta_api": false
}
}
---
# secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: app-secrets
type: Opaque
stringData:
DATABASE_URL: postgres://user:pass@db:5432/app
API_KEY: sk-your-api-key-here
---
# deployment using configmap and secrets
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
template:
spec:
containers:
- name: app
image: myapp: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.json
# kubectl create configmap app-config --from-file=config.properties
# kubectl create secret generic app-secrets --from-literal=API_KEY=valueUse Cases
- Externalizing application configuration in K8s
- Securely managing sensitive credentials
- Sharing configuration across multiple pods
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
yamlbeginner
Kubernetes ConfigMap and Secret Management
Create and use ConfigMaps and Secrets for application configuration with env vars and volume mounts.
Best for: Managing application configuration in Kubernetes
#kubernetes#configmap
bashadvanced
Kubernetes Deployment Configuration
Production-ready Kubernetes deployment with replicas, resource limits, health checks, and rolling updates.
Best for: Production container orchestration
#kubernetes#deployment
bashintermediate
Nginx Reverse Proxy Configuration
Nginx config to reverse-proxy requests to a backend with WebSocket support and security headers.
Best for: Serving Node.js apps behind Nginx
#nginx#reverse-proxy
bashbeginner
Environment File Loader Script
Bash script that safely loads environment variables from a .env file with validation and defaults.
Best for: Loading config before starting services
#env#bash