Kubernetes configmaps: How to update configmap automatically into pods?

We often come acorss following questions while working with ConfigMap and secret are as follows;

  • How to Updating Kubernetes Deployments on a ConfigMap Change?
  • How Mounted ConfigMap is updated automatically in pods?
  • While changing in configmap it doesn’t reflect automatically, every time I have to restart the pod. How can I do it automatically?

Answer:

To update a configmap or secret resource which depends on a deployment(pod). Obviously, updating them is not a big deal. But how would you notify to relevant deployment/pod?

Method 1: Manual restart a pod/deploy which would update volume with latest configmaps and secrets.

kubectl v1.15 now provides a rollout restart sub-command that allows you to restart Pods in a Deployment – taking into account your surge/unavailability config – and thus have them pick up changes to a referenced ConfigMap, Secret or similar. It’s worth noting that you can use this with clusters older than v1.15, as it’s implemented in the client.

Example usage: kubectl rollout restart deploy/admission-control to restart a specific deployment. Easy as that!

$ kubectl rollout restart deploy nginx -n dev

Method 2: Automatic how would you notify to relevant deployment/pod on configmaps and secrets changes?

There are very good reference for this scnario are given below;

  • https://medium.com/@harik8/kubectl-restart-po-deploy-a5b4c6d523fe
  • https://blog.questionable.services/article/kubernetes-deployments-configmap-change/
Rajesh Kumar
Total Page Visits: 10 - Today Page Visits: 1