How can I trigger an update of a Deployment when fields in a ConfigMap are updated?


#1

I see there’s a bit of conversation about this here https://stackoverflow.com/questions/37317003/restart-pods-when-configmap-updates-in-kubernetes and in the kubernetes issue here: https://github.com/kubernetes/kubernetes/issues/22368

Assuming I have a deployment that mounts a volume from a config map or uses envFrom using a configmap, how can I ensure that my deployment gets recreated when the underlying config map changes?

Example

Some fields omitted for brevity / clarity. How can I ensure when the ConfigOption changes that the Deployment gets updated?

---
apiVersion: v1
kind: ConfigMap
metadata: 
  name: appconfig
data:
  DATABASE_URL: {{repl ConfigOption "db_url"}}
---
apiVersion: apps/v1
kind: Deployment
spec:
  template:
    spec:
      containers:
        - name: myapp
          image: mycompany/myapp:1.0.0
          envFrom:
            - configMap:
                name: appconfig