Update configmap without restarting POD
Updating the config map in Kubernetes POD requires the restart of POD. A possible approach to auto-update configmap inside pod without restart is mounting it’s content as volume.
Kubernetes auto-updates the config map into POD if mounted as a volume, however, it has a limitation like it won’t work if subpath used.
The kubelet checks whether the mounted ConfigMap is fresh on every periodic sync. Auto-update is not real-time, it takes time but it updates the config map without restart.
ConfigMaps injected as environment variables are not updated automatically and require a pod restart.
Official document link : https://kubernetes.io/docs/concepts/configuration/configmap/#mounted-configmaps-are-updated-automatically
Pre-requisites
K8s cluster running on Minikube, Docker desktop, GKE, EKS, OKE anywhere
Deploy the YAML
kubectl apply -f
apiVersion: v1
kind: ConfigMap
metadata:
name: test-config
data:
hello: world
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
selector:
matchLabels:
app: test
replicas: 1
template:
metadata:
labels:
app: test
spec:
containers:
- name: configmaptestapp
image: <Image>
volumeMounts:
- mountPath: /config
name: data-volume
ports:
- containerPort: 80
volumes:
- name: data-volume
configMap:
name: test-configSo we can use this option to auto-update the volume with configmap.

Join FAUN: Website 💻|Podcast 🎙️|Twitter 🐦|Facebook 👥|Instagram 📷|Facebook Group 🗣️|Linkedin Group 💬| Slack 📱|Cloud Native News 📰|More.
If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇






