Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Lists or triple dashes to put multiple Kubernetes objects in one YAML file: purely a stylistic choice?

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
like image 847
erstaples Avatar asked May 25 '18 16:05

erstaples


People also ask

What does 3 dashes mean in YAML?

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.

How do I merge multiple YAML files?

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.

Is hyphen allowed in YAML?

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.

What four fields are required in YAML files of Kubernetes?

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.


1 Answers

I can think of two reasons:

  1. Because the Kubernetes API works with JSON and in JSON there is no ---
  2. Maybe the kind List is meant only for responses.
like image 182
Ignacio Millán Avatar answered Sep 29 '22 14:09

Ignacio Millán