我正在尝试将文件 probes.json 挂载到图像。我开始尝试通过手动指定值来创建类似于我的 probes.json 文件的配置映射。
但是,当我应用复制器 Controller 时,出现错误。
我应该如何将我的 JSON 文件传递给我的配置映射/如何在数据参数中指定我的值?
我尝试了以下步骤,但出现错误。
$ cat probes.json
[
{
"id": "F",
"url": "http://frontend.stars:80/status"
},
{
"id": "B",
"url": "http://backend.stars:6379/status"
},
{
"id": "C",
"url": "http://client.stars:9000/status"
}
]
配置图:
apiVersion: v1
kind: ConfigMap
metadata:
name: my-vol-config
namespace: stars
data:
id: F
id: B
id: C
F: |
url: http://frontend.stars:80/status
B: |
url: http://backend.stars:6379/status
C: |
url: http://client.stars:9000/status
副本容器:
apiVersion: v1
kind: ReplicationController
metadata:
name: management-ui
namespace: stars
spec:
replicas: 1
template:
metadata:
labels:
role: management-ui
spec:
containers:
- name: management-ui
image: calico/star-collect:v0.1.0
imagePullPolicy: Always
ports:
- containerPort: 9001
volumeMounts:
name: config-volume
- mountPath: /star/probes.json
volumes:
- name: config-volume
configMap:
name: my-vol-config
错误:
kubectl apply -f calico-namespace/management-ui.yaml
service "management-ui" unchanged
error: error converting YAML to JSON: yaml: line 20: did not find expected key
最佳答案
这部分,-
应该在 volumeMounts
name:
volumeMounts:
name: config-volume
- mountPath: /star/probes.json
像这样:
volumeMounts:
- name: config-volume
mountPath: /star/probes.json
关于json - json格式的Kubernetes configmap错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52619235/