I have been learning Kubernetes intermittently for over a year now.
The hardest part for me is the YAML configurations. Usually, a configuration file contains an apiVersion, kind, metadata, and spec. And then spec contains template, which contains spec again. And this is not always the same. Formats differ for each different kind. I have to memorize a lot of things, and I have to check every time against a reference.
What is the best way to learn Kubernetes configurations? Do we have to grab configuration files and apply them every time instead of writing them? Is this the recommended way?
This question is part of the 100K Member Contest - don't forget to kudo the original contest post to be entered.
Based on my experience, you don't have to memorize each and every single YAML lines. There are a few objects that you can actually generate them using imperative way. For example `kubectl run` would create a pod for you, but you would be able to get the YAML of it if you decide to do so, by adding `-o yaml`.
This is actually similar to what we did when we start to learn a programming language, we don't really memorize the syntax, we start by understanding the concept and design, then practice, then slowly internalize it.
Take your time, no one will penalize you if you have to refer to Kubernetes page every now and then - in fact, even the real expert will still need to do so. Most importantly, have fun!
The way i learned writing yaml files is by understanding the hierarchy of the objects ex: name is a sub-object of metadata. Another handy technique is using oc/kubectl explain command
Understand the basic structure and the components "keywords to use in yaml files", Kube-by-example offers awesome resource on the different flavors of yaml files one might encounter in a Kubernetes env or learn ansible yaml basics.
From my point of view, there is no need to learn to type the configuration files by hand.
You can either create resources via the “imperative” approach, that is use commands to create the resources (eg. kubectl create deployment --image …), or use the “declarative” approach to create a file using a YAML manifest file (kubectl apply -f manifest.yaml).
You can inspect what YAML is generated with the “imperative” commands by doing a dry-run like this:
$ kubectl create deployment --image nginx:alpine --dry-run=client -o yaml > deployment.yaml
Often you want for kubectl to create all the YAML boilerplate and then configure the resource according to your needs (add labels, annotations, etc.).
I recommend you to learn the things you can do with the kubectl tool like patching or custom columns, as well as JSONPath. That will give you a great understanding on the resources and their fields instead of just learning the YAML syntax alone.
Managing Kubernetes Objects Using Imperative Commands
Declarative Management of Kubernetes Objects Using Configuration Files
kubectl cheat sheet