Auto Rolling Restart K8 pods when change in ConfigMap through Stakater Reloader
2 min readJul 12, 2021
Stakater Reloader Setup
helm repo add stakater https://stakater.github.io/stakater-charts
helm repo update
helm install stakater/reloader --generate-name
Create a helm chart with Deployment with ConfigMap:
test-config-change
|-values.yaml
|-Chart.yaml
|-templates
| |-configmap.yaml
| |-deployment.yaml
Sample Deployment file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-config-change
annotations:
reloader.stakater.com/search: "true"
spec:
replicas: 2
selector:
matchLabels:
app.kubernetes.io/name: nginx
template:
metadata:
labels:
app.kubernetes.io/name: nginx
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: config-volume
mountPath: /etc/nginx/conf.d/
volumes:
- name: config-volume
configMap:
name: nginx-cm
Sample ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-cm
annotations:
reloader.stakater.com/match: "true"
data:
data-1: value-1
data-2: value-2
Deploy helm chart
helm install test-config-change test-config-change -n <namespace>
List the pods
kubectl get pods -n <namespace>test-config-change-587b5cdb9d-12345 1/1 Running 0 1h
test-config-change-587b5cdb9d-23456 1/1 Running 0 1h
List Configmap
kubectl get configmaps -n <namespace>NAME DATA AGE
nginx-cm 2 1h
Edit ConfigMap and Update Data:
kubectl edit configmap nginx-cm -n <namespace>data:
data-1: value-5
data-2: value-6
List the pods again:
kubectl get pods -n <namespace>
test-config-change-5ffb46996-dks6g 1/1 Running 0 12s
test-config-change-5ffb46996-th7c4 1/1 Running 0 14s