json格式的Kubernetes configmap错误

use*_*_02 3 json kubernetes

我正在尝试将文件probes.json挂载到图像。我首先尝试通过手动指定值来创建类似于我的probes.json文件的configmap。

但是,当我应用复制器控制器时,出现错误。

如何将JSON文件传递到configmap /如何在data参数中指定值?

我尝试了以下步骤,但是出现错误。

$ 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"
  }
]
Run Code Online (Sandbox Code Playgroud)

配置图:

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
Run Code Online (Sandbox Code Playgroud)

ReplicaContainer:

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
Run Code Online (Sandbox Code Playgroud)

错误:

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
Run Code Online (Sandbox Code Playgroud)

sta*_*cks 5

这部分,-应该name:放在第一行volumeMounts

    volumeMounts:
      name: config-volume
    - mountPath: /star/probes.json
Run Code Online (Sandbox Code Playgroud)

像这样:

    volumeMounts:
      - name: config-volume
        mountPath: /star/probes.json
Run Code Online (Sandbox Code Playgroud)