Hello. I have a question about YAML but it's related to that course. To be hones . . .

Vad Ars:
Hello. I have a question about YAML but it’s related to that course. To be honest I can’t still understand it at all. I’ve passed YAML course twice, completed all Labs etc, but I still can’t understand it completely like below:

apiVersion: v1
kind: Pod
metadata:
labels:
name: webapp-color
name: webapp-color
namespace: default
spec:
containers:
- envFrom:
- configMapRef:
name: webapp-config-map
image: kodekloud/webapp-color
name: webapp-color

I can’t understand when and where in kubernetes yaml use “-”. Like “spec” section. How to determine where should I use “-” and another “-” under it? How do I know where I must to use an array, where I have to use dictionary etc?
Let’s imagine that I’m going to write a yaml file from scratch by not involving any IDE. I still can’t understand why for example “spec:” is not a list of dictionaries or just list etc. I’m totally lost here. Right now it’s just an example above. I would like to understand the principles. Thanks

Al West:
So most people can’t write out perfect yaml that will work first time. A combination of reading the documentation and trial & error will get you there. Also with Kubernetes you can use kubectl to generate a yaml file that you can capture and edit by adding --dry-run=client -o aml to your command.

Vad Ars:
I know about how to generate that file and then edit it according to my needs but right now I’m just guessing “work or not work” while implementing my changes to that file

Alistair Mackay:
Also kubectl explain can help

➜  ~ kubectl explain pod.spec
KIND:     Pod
VERSION:  v1

RESOURCE: spec <Object>

The RESOURCE type <Object> means that spec is a dictionary

➜  ~ kubectl explain pod.spec.containers
KIND:     Pod
VERSION:  v1

RESOURCE: containers <[]Object>

Here <[]Object> means list of dictionary where each container is a dictionary

➜  ~ kubectl explain pod.spec.containers.command
KIND:     Pod
VERSION:  v1

FIELD:    command <[]string>

Here <[]String> means a simple list of strings, like

- these
- are
- some
- strings

Al West:
Also for checking yaml files you can use yamllint