How to update configmap on POD without restart

[How to apply the configMap changes withOut restarting pods.]

MouliVeera
1 min readAug 24, 2022
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

--

--

MouliVeera
MouliVeera

Written by MouliVeera

Mouli is a seasoned DevOps Engineer with expertise in designing and optimising CI/CD pipelines, containerisation with Docker and Kubernetes.

Responses (4)