List
API objects and triple dashes (---
) can both be used to denote multiple objects in a single YAML file. Therefore, why do Lists exist when triple dashes accomplish the same thing (in my opinion) in a cleaner way? Are there any cases in which a List would be preferred over triple dashes, or is this purely a stylistic choice?
For example, these two YAML files both produce the same two ServiceAccount
objects (chosen for brevity):
my-serviceaccounts1.yaml
apiVersion: v1
kind: List
metadata: {}
items:
- apiVersion: v1
kind: ServiceAccount
metadata:
name: my-app
- apiVersion: v1
kind: ServiceAccount
metadata:
name: my-other-app
my-serviceaccounts2.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: my-app
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: my-other-app
The file starts with three dashes. These dashes indicate the start of a new YAML document. YAML supports multiple documents, and compliant parsers will recognize each set of dashes as the beginning of a new one. Next, we see the construct that makes up most of a typical YAML document: a key-value pair.
Yaml files can be merged using the 'merge' command. Each additional file merged with the first file will set values for any key not existing already or where the key has no value.
Summary. Items of a list in YAML are represented by preceding it with - (hyphen). Key value pairs in YAML are represented as <key>:<value> . YAML is case sensitive.
Required Fields apiVersion - Which version of the Kubernetes API you're using to create this object. kind - What kind of object you want to create. metadata - Data that helps uniquely identify the object, including a name string, UID , and optional namespace. spec - What state you desire for the object.
I can think of two reasons:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With