How to initialize a config file without overwriting mountPath

4/5/2019

I need to place a config file default.json in a container mountPath that already have other config files. The way I tried to do this, seems to overwrite the path causing the system not to see the other files in the same directory.

Any ideas how I can do this?

The below code hide the other files from the system.

initContainers:
        - name: install
          image: busybox
          command:
          - wget
          - "-O"
          - "/usr/share/nginx/html/config/default.json"
          - https://s3.eu-central-1.amazonaws.com/.../default.json
          volumeMounts:
            - name: console-config
              mountPath: "/usr/share/nginx/html/config"      
      volumes:
        - name: console-config
          emptyDir: {}
-- Anton Swanevelder
kubernetes

1 Answer

4/5/2019

Using subPath field, you can mount the directory or file without overwriting other files, you can find more information here subPath

   initContainers:
        - name: install
          image: busybox
          command:
          - wget
          - "-O"
          - "/usr/share/nginx/html/config/default.json"
          - https://s3.eu-central-1.amazonaws.com/.../default.json
          volumeMounts:
            - name: console-config
              mountPath: "/usr/share/nginx/html/config"
              subPath: config                      
      volumes:
        - name: console-config
          emptyDir: {}
-- Suresh Vishnoi
Source: StackOverflow