2

Summary

Should K8s config maps be accessed via the ..data symlink or via the normal path?

Details

We are attaching a configmap to a pod via

...
        volumeMounts:
        - mountPath: /var/opt/app_configs
          name: app-config
          readOnly: true
...
      volumes:
      - name: app-config
        configMap:
          name: app-kubernetes-configmap

Then, it seems, within the pod we can access the config files in either of the below ways

  • Using Kubernetes symlink - /var/opt/app_configs/..data/app-config.yaml
  • "Normal" path to config file - /var/opt/app_configs/app-config.yaml

What is recommended?

1 Answers1

0

The main difference to look for here is that:

  • If the ConfigMap is mounted with a subPath, it won’t update until the pod restarts.

  • If you mount it as a directory (without subPath), your container will get a continuously up-to-date config file with no restarts necessary.

Example of using subPath:

$ kubectl -n production exec go-conf-example-6b4cb86569-22vqv -- ls -lha /app/configfiles 
total 20K    
drwxr-xr-x    1 root     root        4.0K Mar  3 19:34 .
drwxr-xr-x    1 app      app         4.0K Mar  3 19:34 ..
-rw-r--r--    1 root     root          42 Mar  3 19:34 config.json
-rw-r--r--    1 root     root          47 Mar  3 19:34 database.yml

Example of using a directory:

$ kubectl -n production exec go-conf-example-67c768c6fc-ccpwl -- ls -lha /app/configfiles 
total 12K    
drwxrwxrwx    3 root     root        4.0K Mar  3 19:40 .
drwxr-xr-x    1 app      app         4.0K Mar  3 19:34 ..
drwxr-xr-x    2 root     root        4.0K Mar  3 19:40 ..2020_03_03_16_40_36.675612011
lrwxrwxrwx    1 root     root          31 Mar  3 19:40 ..data -> ..2020_03_03_16_40_36.675612011
lrwxrwxrwx    1 root     root          18 Mar  3 19:40 config.json -> ..data/config.json
lrwxrwxrwx    1 root     root          19 Mar  3 19:40 database.yml -> ..data/database.yml

Notice that the file inside the container is actually a symlink.

So, to answer your question:

Should K8s config maps be accessed via the ..data symlink or via the normal path?

In your use case you can go both ways as you are mounting a directory.

My friend Vitalii also shared some light on this topic with his answer.