YAML Multi-Document Streams

Document separators, multi-resource YAML files, and commands for splitting, filtering, and validating streamed YAML.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Multi-document YAML

Store multiple YAML documents in one file with `---` separators.

Two YAML documents in one file

Use `---` to separate resources or configs.

yamlANYyamlmulti-documentseparator
yaml
app: api
port: 8080
---
app: worker
port: 9090
Notes

Common in Kubernetes and other tools that process a stream of YAML documents.

Explicit document end marker

Use `...` to mark the end of a document when needed.

yamlANYyamldocument-end
yaml
name: sample
...
Notes

The end marker is less common, but it can help in streamed or generated YAML.

Apply a multi-document manifest

Send several Kubernetes resources in one file.

bashANYyamlkubernetesmulti-document
bash
kubectl apply -f stack.yaml
Notes

Kubernetes commonly uses one file containing Namespace, Deployment, Service, Ingress, and more.

Split YAML documents into separate files

Write each YAML document to its own output file.

bashANYyamlyqsplit
bash
yq -s '.metadata.name' stack.yaml
Notes

Useful when a generated manifest needs to be broken into individual resource files.

Select and inspect documents

Commands for reading the right document from a YAML stream.

Read the first YAML document

Query the first document in a stream.

bashANYyamlyqdocument-index
bash
yq 'select(documentIndex == 0)' stack.yaml
Notes

Helpful when a file contains multiple resources and you only need one.

Select Kubernetes documents by kind

Filter documents in a manifest stream.

bashANYyamlyqkubernetesfilter
bash
yq 'select(.kind == "Deployment")' stack.yaml
Notes

A fast way to inspect or extract just one type of resource from a large manifest.

Render Helm templates to YAML

Generate YAML output for inspection before deployment.

bashANYyamlhelmrender
bash
helm template myapp ./chart
Notes

Rendered YAML is easier to lint, diff, and review before applying changes.

Recommended next

No recommendations yet.