Welcome to the Linux Foundation Forum!

Yaml Understanding Help

Hi,

I've done some googling and I'm still looking for a good example of a fully flushed out YAML file that has comments.
I'm having a tough time understanding where each key value pair go as well was the formatting.
I understand that most use two spaces but I don't really understand why some files have different key values.

For example,

I'm looking at the batch job.yaml file in the lab. I don't have a good grasp why there is another spec in the file as well has how the indentation is working and why containers is at the bottom. I understand it is based on what kind the application is but I still don't seem to understand what is needed for what kind of application I'd deploy in kubernetes.

I feel that this is something very basic that I need a good link or something to I can understand how to read and create the YAML files better.

I see
spec:
completions: 5
template:
spec:
containers:

Thanks.

Comments

  • btanoue
    btanoue Posts: 59

    Ignore the formatting. I don't see a code block button.

  • fcioanca
    fcioanca Posts: 2,157
    edited May 2019

    @btanoue You can use the code formatting option (see the screenshot attached)!

  • btanoue
    btanoue Posts: 59
    edited May 2019

    Thank You! I was looking for a button and never checked the Paragraph button. Most sites have a dedicated code button.

  • btanoue
    btanoue Posts: 59
    edited May 2019

    apiVersion: batch/v1
    kind: Job
    metadata:
    name: sleepy
    spec:
    completions: 5
    parallelism: 2
    activeDeadlineSeconds: 15
    template:
    spec:
    containers:
    - name: resting
    image: busybox
    command: ["/bin/sleep"]
    args: ["5"]
    restartPolicy: Never

  • serewicz
    serewicz Posts: 1,000

    Hello,

    When trying to figure out the indentation of YAML and what it will become I like to paste into the right side of https://json2yaml.com/ As kube-apiserver persists data to etcd in JSON, you can see why various sections have their indentation.

    The reason you will find more than one spec: entry in a file has to do with the nature of the watch-loop, or controller, which will use the code. Some controllers monitor and create other controllers. As a result they pass along the other spec to the watched controller. For example if you look at the YAML of a Deployment you will notice there is spec information for the deployment, spec information for the replicaSet it creates and spec information for the pods the replicaset will create. In the Jobs area a CronJob creates a job which creates a Pod. So you would also have more than one spec area in the YAML.

    Hopefully that helps.

    Regards,

  • btanoue
    btanoue Posts: 59

    Hi,

    Thanks, I'll take a look at it. I'm just worried I'll spend way too much time on the exam for not indenting correctly. I don't think there is a syntax fixer we can use during the test.

  • serewicz
    serewicz Posts: 1,000

    Hello,

    Indeed. Remember you can use two websites during the exam, reference the Exam Guide to learn more. You may want to bookmark pages in the browser you will use during the exam, to have an example of the more complex YAML files.

    Good luck on the exam.

  • btanoue
    btanoue Posts: 59

    Thank You, I'll start to look at that.

Categories

Upcoming Training