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
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
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