Persistent Parsing errors

I’m back using Docker after several years away. So I followed the nice documentation “Orientation and setup” up to starting Kubernetes which is up and running fine on my Mac Pro.

Then, in order to test that part, I have cut and pasted the test pod.yaml from the docimentation and got into infinite parsing errors…

Did some research and I went to yamlint and YAML Validator to clean it up. But even with this flagged cleaned code, I still get parsing errors. I have modified the file with vi to ensure only spaces no tabs are in the test yaml file.

Original copy and pasted code from “Orientation and setup” and validated by Code Beautify:

 apiVersion: v1
 kind: Pod
 metadata:
   name: demo
 spec:
   containers:
   - name: testpod
     image: alpine:3.5
     command: ["ping", "8.8.8.8"]

-> kubectl apply -f pod.yaml
error: error parsing pod.yaml: error converting YAML to JSON: yaml: line 2: mapping values are not allowed in this context :worried:

Then a clean one with no indent validated with yamlint

apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:

  • name: testpod
    image: alpine:3.5
    command: [“ping”, “8.8.8.8”]

->kubectl apply -f pod.yaml
error: error validating “pod.yaml”: error validating data: [ValidationError(Pod): unknown field “command” in io.k8s.api.core.v1.Pod, ValidationError(Pod): unknown field “containers” in io.k8s.api.core.v1.Pod, ValidationError(Pod): unknown field “image” in io.k8s.api.core.v1.Pod, ValidationError(Pod): unknown field “name” in io.k8s.api.core.v1.Pod]; if you choose to ignore these errors, turn validation off with --validate=false

Seems I am lost already just a the beginning of setting things up, any idea what is wrong?

Mac OS : Mojave 10.14.2
Docker Desktop : 2.1.0.4 (39773) - stable
Kuvernetes : v1.14.7

Thanks.

1 Like

I ran into the exact same problem:

kubectl apply -f pod.yaml
error: error parsing pod.yaml: error converting YAML to JSON: yaml: line 2: mapping values are not allowed in this context

Turns out I had no space before apiVersion:

 apiVersion: v1
 kind: Pod
 metadata:
   name: demo
 spec:
   containers:
   - name: testpod
     image: alpine:3.5
     command: ["ping", "8.8.8.8"]

Versus:

apiVersion: v1
 kind: Pod
 metadata:
   name: demo
 spec:
   containers:
   - name: testpod
     image: alpine:3.5
     command: ["ping", "8.8.8.8"]

Note the missing space on the first line before apiVersion: v1.

I recommend removing all whitespace before the toplevel elements and 2 spaces per indentation:

apiVersion: v1
kind: Pod
metadata:
  name: demo
spec:
  containers:
  - name: testpod
    image: alpine:3.5
    command: ["ping", "8.8.8.8"]

I don’t like the idea of doing a query to check if the data can probably be inserted because it adds round-trips for a check the database server does anyway and it does not even work in every case because the database can change between the SELECT and the INSERT myprepaidcenter