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

5/25/2018

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
-- erstaples
kubernetes
yaml

1 Answer

5/25/2018

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.
-- Ignacio Millán
Source: StackOverflow