Skip to main content
veronica

1 year ago

kubernetes converting issue

hello guys 

 
when creating my configmap i followed the instruction to the letter and i keep getting this error 

error: error parsing pod-config.yaml: error converting YAML to JSON: yaml: line 15: did not find expected key

this is my yaml file for the pod-config.yaml 

apiVersion: v1
kind: Pod
metadata:
- name: config-test-pod
spec:
containers:
- name: test-container
image: busybox
command: [ "/bin/sh", "-C", "env" ]
env:
- name: WHAT_SCHOOL
valueFrom:
confgMapKeyRef:
name: my-map
key: school
restartPolicy: Never

guys can you please help 

thanks 

Image of wboyd
wboyd
1 year ago
I think it's a problem with your whitespace. Yaml files are very particular about indentation. Try this:
apiVersion: v1
kind: Pod
metadata:
  - name: config-test-pod
spec:
  containers:
  - name: test-container
    image: busybox
    command: [ "/bin/sh", "-C", "env" ]
    env:
    - name: WHAT_SCHOOL
      valueFrom:
        confgMapKeyRef:
          name: my-map
          key: school
    restartPolicy: Never
Image of viccab
viccab
1 year ago
name in metadata should not have a hyphen.
confgMapKeyRef is mispelled.
restartPolicy should be in line with containers.

apiVersion: v1
kind: Pod
metadata:
  name: config-test-pod
spec:
  containers:
  - name: test-container
    image: busybox
    command: [ "/bin/sh", "-C", "env" ]
    env:
    - name: WHAT_SCHOOL
      valueFrom:
        configMapKeyRef:
          name: my-map
          key: school
  restartPolicy: Never


Image of veronica
veronica
1 year ago
hello 
same things guys 

apiVersion: v1
kind: Pod
metadata:
  name: config-test-pod
spec:
  containers:
    - name: test-container
      image: busybox
      command: [ "/bin/sh", "-C", "env" ]
      env:
      - name: WHAT_SCHOOL
        valueFrom:
          confgMapKeyRef:
            name: my-map
            key: school
 restartPolicy: Never

same error 

error: error parsing pod-config.yaml: error converting YAML to JSON: yaml: line 15: did not find expected key

even with the spelling correction 

same result 
Image of veronica
veronica
1 year ago
it worked guys thanks. 
just deleted my yaml file and copied yours into it 
thanks again 
Image of mormoroth
mormoroth
1 year ago
 @veronica

 you can use https://www.json2yaml.com to double check your yaml files.