1

I have the following yaml file:

---
apiVersion: v1
kind: pod
metadata:
    name: Tesing_for_Image_pull -----------> 1
    spec:
        containers:
        - name: mysql ------------------------> 2
          image: mysql ----------> 3
          imagePullPolicy: Always ------------->4
          command: ["echo", "SUCCESS"]  -------------------> 5

After running kubectl create -f my_yaml.yaml I get the following error:

error: error converting YAML to JSON: yaml: line 10: did not find expected key

UPDATE: With yamllint I get the following error:

root@debian:~# yamllint my_yaml.yaml
my_yaml.yaml
  8:9       error    wrong indentation: expected 12 but found 8  (indentation)
  11:41     error    syntax error: expected <block end>, but found '<scalar>'

Where is my problem and how can I solve it?

1
  • What is with the - before name in line 8? And what is with all the ------------->'s? Commented Dec 7, 2019 at 20:13

1 Answer 1

2

The simple pod example YAML for Kubernetes shows that the 'metadata' and 'spec' elements required are at the top level of the definition. The kubectl command is most likely failing because it cannot find the 'spec' element, which defines the specification of the pod.

You seem to be testing the image pull configuration, and you have specified that you simply want to run echo SUCCESS inside the container. Considering both these conditions, it would be preferable to pull down bash image instead of the mysql image.

The following alternate YAML should work for your needs:

---
apiVersion: v1
kind: Pod
metadata:
  name: testing-for-image-pull
spec:
  containers:
  - name: bash
    image: bash
    imagePullPolicy: Always
    command: ["echo"]
    args: ["SUCCESS"]

The following changes have been made from the original YAML file: 1) The kind element has been corrected to the value Pod. 2) The name of the pod has been changed to fit Kubernetes requirements (lowercase DNS-like name). 3) The image and name elements have been modified to use the bash image. 4) The command definition has been changed to use the command and args keys instead.

Note that YAML uses spaces instead of tabs for indentation, and the suggested syntax for YAML is to use two spaces per level of indentation instead of the traditional four spaces.

For more example YAML files, refer to the Kubernetes website repository on GitHub.

5
  • With your yaml file I got the error error: error validating "Tesing_for_Image_pull.yaml": error validating data: couldn't find type: v1.pod; if you choose to ignore these errors, turn validation off with --validate=false Commented Dec 9, 2019 at 11:05
  • @PersianGulf I'm sorry, that was a typo I had missed. It should be kind: Pod, with a capital P. I'll fix my answer accordingly. I think this is a good time to point out that Kubernetes is generally terrible at producing meaningful error messages. The solutions are usually documented somewhere, though - case in point. Commented Dec 9, 2019 at 15:50
  • I tested with capital 'P' and lower P, Both have error. Commented Dec 9, 2019 at 17:24
  • @PersianGulf Sorry for the late reply, but I've done some testing and have included an alternate YAML in my answer. This one's been tested on a Minikube instance, so it should work correctly for you. Commented Dec 14, 2019 at 15:46
  • With the above answer, solved my problem. But I have problem with devops.stackexchange.com/questions/10110/… , You make me happy if you answer it. Commented Dec 14, 2019 at 16:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.