已安装的 ConfigMap 卷未完全提供

Mounted ConfigMap volume is not served entirely

ASP.NET wwwroot/config/config.json

中带有外部配置的核心 SPA

config.json 的内容:

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

当文件没有被 ConfigMap 覆盖时,它工作正常,我能够获得文件的全部内容。

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

当ConfigMap数据用Volume挂载到这个路径时,不会全部返回。

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

文件存在于 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

您是说 /app/wwwroot/config 目录中的任何其他文件在从 ConfigMap 挂载到该位置时都消失了吗?

你试过了吗projected音量:

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

编辑: 对于那些可能遇到此类问题但未通读帖子下方消息的人 - 在与@edbighead 交换消息后,另一个建议是使用 subPath 在 Deployment 中保留配置目录可写,因为 ConfigMap 卷安装是只读的:

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

这显然 解决了问题