3

I am trying to mount a file probes.json to an image. I started with trying to create a configmap similar to my probes.json file by manually specifying the values.

However, when I apply the replicator controller, I am getting an error.

How should I pass my JSON file to my configmap / how can I specify my values in data parameter?

I tried the below steps, however, I got an error.

$ 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"
  }
]

Configmap:

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

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

Error:

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
2
  • 1
    I think the lastest yaml is not valid. Check with yamllint.com for example. I think you will need to remove the dashes before the keys and it will do Commented Oct 3, 2018 at 3:24
  • @Tomás Gonzalez Dowling still the same error Commented Oct 3, 2018 at 3:30

2 Answers 2

6

This part, - should be with name: on first line under volumeMounts

    volumeMounts:
      name: config-volume
    - mountPath: /star/probes.json

Like so:

    volumeMounts:
      - name: config-volume
        mountPath: /star/probes.json
Sign up to request clarification or add additional context in comments.

Comments

4

I wanted to add more points that i have learned today,

Mounting a file using the below code will delete any files under the directory in this case star directory in the container.

-    volumeMounts:
      - name: config-volume
        mountPath: /star/probes.json

to solve it we should use subpath

  volumeMounts:
    - name: "config-volume"
      mountPath: "/star/probes.json"
      subPath: "probes.json"

Instead of fiddling on how to pass key-value pairs into the data , try passing as json file and remember to specify the namespace while creating the configmap

In my example: I have probes.json and i tried to pass it as such without passing each value to my data. I used the below command to create my configmap

kubectl create configmap config --namespace stars --from-file calico-namespace/probes.json

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.