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!
Practise, Practise - participate and contribute to the open-source world
May be simple but it was the most robust then...working on puppet helped me work on the yaml.
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
I am a beginner, will have to study it first and will let you know
Your question: What is the best way to learn Kubernetes configurations?
My answer: By doing, doing, and doing some more!!!
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.
References
Managing Kubernetes Objects Using Imperative Commands
- https://kubernetes.io/docs/tasks/manage-kubernetes-objects/imperative-command/
Declarative Management of Kubernetes Objects Using Configuration Files
- https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/
kubectl cheat sheet
- https://kubernetes.io/docs/reference/kubectl/cheatsheet/
JSONPath Support
- https://kubernetes.io/docs/reference/kubectl/jsonpath/
I'm a novice at yaml, so I have to keep at it and keep learning especially from others. A smart person is one that is surrounded by smarter people!
The big question is not to decorate, but to interpret what you want. And the community helps a lot. Thank you all for your support and opinions.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.