gotchaModeratepending
Gotcha: Kubernetes ConfigMap updates don't trigger pod restart
Viewed 0 times
configmap updatepod restartconfigmap hashrollout restartreloader
Error Messages
Problem
Updating a ConfigMap doesn't automatically restart pods that use it, leaving them with stale configuration.
Solution
ConfigMap update propagation:
# Problem: Pod uses ConfigMap as env vars
# Updating ConfigMap does NOT restart the pod!
# Solution 1: Add ConfigMap hash as annotation
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
template:
metadata:
annotations:
# Change this when ConfigMap changes -> triggers rollout
configmap-hash: "abc123" # Update manually or via CI
spec:
containers:
- name: app
envFrom:
- configMapRef:
name: myapp-config
# Solution 2: Use kubectl rollout restart
kubectl rollout restart deployment/myapp
# Triggers a rolling restart of all pods
# Solution 3: Volume-mounted ConfigMaps DO auto-update!
# (But only for volume mounts, NOT env vars)
spec:
containers:
- name: app
volumeMounts:
- name: config
mountPath: /etc/config
volumes:
- name: config
configMap:
name: myapp-config
# Files in /etc/config update within ~60s
# But your app must watch for file changes!
# Solution 4: Immutable ConfigMaps (Kubernetes 1.21+)
apiVersion: v1
kind: ConfigMap
metadata:
name: myapp-config-v2 # New name for each version
immutable: true
data:
APP_MODE: production
# Update deployment to reference new ConfigMap name
# Old ConfigMap can be garbage collected
# Solution 5: Use Reloader (open source controller)
# https://github.com/stakater/Reloader
# Automatically restarts pods when ConfigMap/Secret changes
metadata:
annotations:
reloader.stakater.com/auto: "true"Why
Kubernetes doesn't restart pods when ConfigMaps change because it could cause unexpected downtime. The tradeoff is that pods can run with stale config until explicitly restarted.
Context
Kubernetes configuration management
Revisions (0)
No revisions yet.