Mounted ConfigMap volume is not served entirely

11/21/2018

ASP.NET Core SPA with external config in wwwroot/config/config.json

Contents of config.json:

{
  "termsAndConditionsLink": "https://some-dev-url.with/legal/terms/"
}

When the file is not being overwritten by a ConfigMap, it works fine and I am able to get the full content of file.

curl https://dev-app.com/config/config.json
{
  "termsAndConditionsLink": "https://some-dev-url.with/legal/terms/"
}

When ConfigMap data is mounted to this path with Volume, it is not returned entirely.

curl https://dev-app.com/config/config.json
{
  "termsAndCon

The file is present in pod:

pwd
/app/wwwroot/config

ls -la
total 12
drwxrwxrwx 3 root root 4096 Nov 20 08:48 .
drwxr-xr-x 6 root root 4096 Nov 20 08:46 ..
drwxr-xr-x 2 root root 4096 Nov 20 08:48 ..2018_11_20_08_48_02.390652870
lrwxrwxrwx 1 root root   31 Nov 20 08:48 ..data ->         ..2018_11_20_08_48_02.390652870
lrwxrwxrwx 1 root root   18 Nov 20 08:48 config.json -> ..data/config.json

cat config.json
{
  "termsAndConditionsLink": "https://some-dev-url.with/legal/terms/"
}

ConfigMap.yaml

kind: ConfigMap
apiVersion: v1
metadata:
  name: my-config
data:
  config.json: |-
    {
      "termsAndConditionsLink": "https://some-dev-url.with/legal/terms/"
    }

Deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-app
  labels:
    ...
spec:
  template:
    metadata:
      labels:
        ...
    spec:
      containers:
        ...
          volumeMounts:
            - name: my-volume
              mountPath: /app/wwwroot/config
      volumes:
        - name: my-volume
          configMap:
            name: my-config
-- edbighead
configmap
google-kubernetes-engine
kubernetes

1 Answer

11/21/2018

Do you mean that any other files in the /app/wwwroot/config directory are gone when mounting a volume at that location from the ConfigMap?

Have you tried projected volume:

volumes:
  - name: my-volume
    projected:
      sources:
      - configMap:
          name: my-config

EDIT: For those that may come across such problem and don't read through the messages below the posts - after exchanging messages with @edbighead, another suggestion was to use subPath in the Deployment to leave the config directory writeable as ConfigMap volume mounts are read-only:

mountPath: /app/wwwroot/config/config.json 
subPath: config.json

That apparently solved the problem.

-- apisim
Source: StackOverflow