ASP.NET Core SPA 与 wwwroot/config/config.json 中的外部配置
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/"
}
配置映射.yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: my-config
data:
config.json: |-
{
"termsAndConditionsLink": "https://some-dev-url.with/legal/terms/"
}
部署.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