A question about YAML syntax

When I read a YAML file,I find several sentences puzzling me:

      containers:      
      - name: demo     
        image: demo:v1      
        imagePullPolicy: IfNotPresent  

Why doesn’t the “-” before “name” need indenting?
I think the list [“name”,“image”, …] should belong to “containers”.

Kubernetes pods can be made up of multiple containers, that’s why containers is an array :+1:

A common example would be a worker container or say a webserver and then another one that is used for shipping logs, or if you’re using a service mesh to act as a ‘router’ to encrypt communication to other pods.

2 Likes

Thanks for your answer.
I know containers is an array,so the “-” before name should be indented,but why doesn’t it do here?

Ahh, sorry -
So for arrays in yaml (yaml spec refers to them as collections), the space doesn’t matter because it can tell it’s an element of a collection by looking for a dash then a space “- “.

Because it can clearly parse the elements, the spacing doesn’t matter.