How to update configmap on POD without restart

ConfigMaps&Pods
  • We can use a few annotations at POD and configMaps to do that.
  • Add below annotations at metadata to configMap
annotations:
reloader.stakater.com/match: "true"
  • Add below annotations at metadata to deployment
annotations:
reloader.stakater.com/search: "true"
  • Reference YAML below

Example:

apiVersion: apps/v1
kind: Deployment
metadata:
name: first-deployment
labels:
app: nginx-test
annotations:
reloader.stakater.com/search: "true"
spec:
### REPLICASET SPEC ####
replicas: 2
selector:
matchLabels:
app: nginx-test
### POD SPEC ###
template:
metadata:
name: mouli
labels:
app: nginx-test
spec:
containers:
- name: chaitu
image: nginx
volumeMounts:
- name: firstdeploy-cm
mountPath: /usr/share/nginx/html/
volumes:
- name: firstdeploy-cm
configMap:
name: firstdeploy-cm
---
apiVersion: v1
kind: ConfigMapmetadata:
name: firstdeploy-cm
annotations:
reloader.stakater.com/match: "true"
data:
index.html: |
<!DOCTYPE html>
<html>
<body>
<h1>This is a TEST NGINX page</h1> <p>By MouliDeepika</p> </body>
</html>
  • Do port-forward to the deploy
kubectl port-forward deploy/first-deployment -n demo 8088:80
  • Open the browser and access https://127.0.0.1:8088
  • Make changes to configmap YAML and APPLY.
  • reload webpage [127.0.0.1:8088], it comes with new configMap values.

Source: https://github.com/stakater/Reloader

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store