How to pull in an already generated ConfigMap to a new pod without regenerating the configmap?

3/12/2020

I have a kustomization file that's generating a ConfigMap and behaving as expected. I need to be able to create a new pod that pulls in the environment variables from that same configMap without regenerating the configMap. In other words, I'm having to do this:

envFrom:
    - configMapRef:
        name: config-name-HASH

but I want to do this:

envFrom:
    - configMapRef:
        name: config-name

without needing to regenerate the ConfigMap with kustomize. I've found PodPresets which would seem to be the fix, but that's in Alpha, so it's not good for my organization.

-- Samuel Henderson
kubernetes
kubernetes-pod

1 Answer

3/12/2020

That is not possible. While ConfigMap volumes update in-place and automatically (so you could switch that and make your app re-read the file when it updates), env vars pulled from a ConfigMap (or Secret, all of this applies to both) are only checked when the pod is launched. The usual workaround is to put a checksum or generation ID of your configmap as an annotation in the pod template which will automatically trigger a rolling update through the Deployment, StatefulSet, or DaemonSet controllers.

-- coderanger
Source: StackOverflow