vsupalov


Finding YAML Examples and Docs For Kubernetes Config Files

A few ways and laces to find information on config file fields for pod, replica set, replication controller and deployment files.

[ kubernetes ]

When new to Kubernetes, it’s sometimes hard to find the information you need to get started. The docs are there, but don’t feel focused enough at times.

Writing resource YAML files can be challenging, if you don’t know what fields are available and what they do.

Here are a few ways to look up info on fields and find examples for files like pods.yaml, rs.yaml, rc.yaml, secret.yaml, svc.yaml, deployment.yml.

Examples in The Docs

The documentation pages have examples of YAML files, which can be a good starting point to see how a simple resource file is supposed to look. For example:

Navigating to a relevant part of the docs and either searching for “yaml” or scrolling through to find examples usually yields results. But those are not detailed and sometimes tricky to find.

Built-In Lookup

This one is great to dive deeper and explore on your own. Use kubectl explain to learn more about available fields and what they mean for any resource. You can install minikube on your dev machine just to have always access to it.

To see all resources, type:

$ kubectl explain

This will list every kind of resource you can look up.

To get all possible field of a service for example, you should use the –recursive flag:

$ kubectl explain service --recursive
# or
$ kubectl explain svc --recursive
# or
$ kubectl explain services --recursive

This will list all possible fields and subfields, which is nice for an overview. As you can see in the example, name variations and short versions work as well.

To get details on a single field, or the fields of an object without subfields, just leave out the –recursive. You can navigate to a particular field using dots.

$ kubectl explain svc.metadata.uid

What happens in the background is, that the Kubernetes API is accessed, and you get parts of the API Swagger documentation. You can read more (but not much more) about the command and parameters here.

Examples From The Kubernetes GitHub Repo

This is a great way to see how things are done by the people who work on Kubernetes. You can check out the examples for files of interest like pod.yaml. You can use the repo search to look for a fragment of the file you’re interested in and go from there.

Charts - Real-World Examples

Helm has becom known as the “package manager for Kubernetes”. There are lots of apps you can simply

$ helm install stable/<app name>

with a single command.

Behind the magic, those packages contain lots of configuration files which can be viewed and used to learn. Those are templates, but after understanding how the templating language works you’ll have a huge number of great projects to refer to.

You can either check out the charts repo if you prefer the GitHub interface, or browse apps on kubeapp.com. For each project, you can view a detailed description and usually navigate to the corresponding repo to see for yourself how they’re structured. Kube Lego is a nice example. Here is the repository.

Get My Weekly Newsletter

Weekly-ish articles about Kubernetes, Docker, DevOps, automation and deployment.

Free goodies too: get a list of my top 12 tools for deployment & automation and more exclusive content I only share with subscribers.