hi guys, in this article i will give tutorial for implement pods auto reloader on kubernetes, imagine you have config apps on configmap or secret, and have changes, if your service/apps not have hot-reloader you must restart your pods manualy
so in this tutorial i will show you how reloader from stakater can handle hot reload when you have changes on configmap or secret
by default reloader will install on namespace default and watches changes secrets and configmaps in all namespaces, you can run command below for install
kubectl apply -f https://raw.githubusercontent.com/stakater/Reloader/master/deployments/kubernetes/reloader.yaml
in reloader we have 2 methode for restart pods when we have changes on configmap or secret
first method
first method will discover deployments/daemonsets/statefulset/rollouts automatically where configmap or secret is being used either via environment variable or from volume mount. And it will perform rolling upgrade on related pods when configmap or secret are updated
for this method you can add annotations on deployment and configmap below
- deployment: reloader.stakater.com/search: “true”
- configmap/secret: reloader.stakater.com/match: “true”
sample like below
apiVersion: apps/v1 kind: Deployment metadata: annotations: reloader.stakater.com/search: "true" name: nginx-deployment labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 envFrom: - configMapRef: name: nginx-configmap ports: - containerPort: 80 --- apiVersion: v1 kind: ConfigMap metadata: annotations: reloader.stakater.com/match: "true" name: nginx-configmap data: domain: "sekolahlinux.com"
second method
second method will discover deployments/daemonsets/statefulset/rollouts automatically where configmap or secret you set on annotation, even the configmap or secret not use as environment variable or from volume mount. And it will perform rolling upgrade on related pods when configmap or secret are updated
for this method you can add annotations on deployment like below
- deployment: configmap.reloader.stakater.com/reload: “nginx-configmap”
- deployment: secret.reloader.stakater.com/reload: “nginx-secret”
and also you can use comma separated list to define multiple secrets or configmap name like below
- deployment: configmap.reloader.stakater.com/reload: “nginx-configmap,app-configmap”
- deployment: secret.reloader.stakater.com/reload: “nginx-secret,app-secret”
sample like below
apiVersion: apps/v1 kind: Deployment metadata: annotations: configmap.reloader.stakater.com/reload: "nginx-configmap" name: nginx-deployment labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80 --- apiVersion: v1 kind: ConfigMap metadata: name: nginx-configmap data: domain: "sekolahlinux.com"
reference link: