ConfigMap from file used in deployment does not update on deploy

Running Kubernetes 1.14 and created a ConfigMap:

kubectl create configmap esquire-config --from-file=config.js=configs/env.cloud-dev.js

Then using the ConfigMap in a deployment like:

...
spec:
      containers:
        volumeMounts:
        - name: esquire-volume
          mountPath: /var/esquire/config
      
      ...

      volumes:
        - name: esquire-volume
          configMap:
            name: esquire-config
            items:
            - key: config.js
              path: config.js
      ...
...

If I rebuild the Docker container and update the Kubernetes deployment using the trick:

kubectl set env deployment --env="UUID=$(uuidgen)" esquire

It recycles the pods, but the ConfigMap on each pod IS NOT UPDATED. What is the process to update the ConfigMap for the deployment and is there any automated way of doing this using the native deployment object?

Did you push an update to the configmap? It’s not automatically watching your workstation’s filesystem. :slight_smile:

So, the --from-file=config.js=configs/env.cloud-dev.js indeed is using my workstation’s filesystem, but actually the config file is also inside the Docker container at configs/env.cloud-dev.js.

Perhaps instead of using a ConfigMap is there a way to create a symbolic link when Kubernetes starts the pod but before it does the readiness probe?

ln -s configs/env.cloud-dev.js configs/config.js

Note: env.cloud-dev.js is environment dependent and filename changes, thus why the link is needed.

If not, is there a way to create a ConfigMap from a file instead in the Docker container instead of my local workstation?


nodesocket

    January 8

So, the --from-file=config.js=configs/env.cloud-dev.js indeed is using my workstation’s filesystem, but actually the config file is also inside the Docker container at configs/env.cloud-dev.js.

If the file is in the container, what is the ConfigMap for? I am confused.

Perhaps instead of using a ConfigMap is there a way to create a symbolic link when Kubernetes starts the pod but before it does the readiness probe?

Is the problem that you don’t know which config file to use? Can you pass that as a flag to your app?

Or is the problem that you want to decouple the container’s lifecycle from the config lifecycle? That is what ConfigMap is for. But you have to tell kubernetes that the config changed. The typical answer is to check the config into git and ‘kubectl apply’ it after commits are made.

Now, caution. ConfigMaps can be dynamically updates, but your app has no control over how fast that rolls out.

Unfortunately not. The container CMD just starts NGINX CMD ["/usr/sbin/nginx", "-c", "/etc/nginx/nginx.conf"]. The build is static HTML content and a JavaScript file loads config/config.js dynamically.

I don’t know of an elegant way to pass configs/env.cloud-dev.js through NGINX so the JavaScript file can dynamically load it. Essentially all I need is a dynamic symbolic link when the pod starts:

# env.cloud-dev.js is dynamic / variable
ln -s configs/env.cloud-dev.js configs/config.js

Passing flag is an elegant solution. But if you really need you can create this simlink using Init Containers - Kubernetes. You can also override the configs/config.js by mounting your ConfigMap in the same place.