Do you know all the YAML tricks and gotchas?

Are there any YAML tips for Kubernetes?

Read along!
1/

Let's cover the basics first.

YAML has three basic rules:

1. Indentation — only 2 or 4 spaces
2. Maps — key-value pairs
3. Lists — collections of things
2/

Maps and lists are the basic building blocks of any YAML file.

Any value that is part of a list or of map's value can be a string, a number, a boolean, `null`, or another dictionary.

In most cases, strings don't require quotes.

But sometimes if you miss them... 💣💥
3/

Apart from edge cases, there are some actual useful features if you write Kubernetes manifests:

- You can use `---` to delimit docs
- You can define snippets with `*` and reference them with `&`
4/

What if you make a mistake?

How do you know? 🤔

You could use:

1. an online YAML linter like yamllint.com
2. a CLI like yamllint.readthedocs.io/en/stable/
3. if you use Visual Studio Code, install the YAML extension from Red Hat for autocomplete marketplace.visualstudio.com/items?itemName…
5/

Is there any useful tool to edit YAML other than by hand?

`yq` mikefarah.github.io/yq/ is a command-line tool designed to transform YAML.

It is similar to another more popular tool called `jq` that focuses on JSON instead of YAML.
6/

That's it! This was a short intro to YAML (and YAML's gotchas). Do you know more tips? Let me know!

You might enjoy the previous threads too! You can find all of them here:

What would you like to see next? Please reply and let me know!

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Daniele Polencic

Daniele Polencic Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @danielepolencic

24 Sep
THREAD: How does the scheduler work in Kubernetes?

The scheduler is in charge of deciding where your pods are deployed in the cluster.

It might sound like an easy job, but it's rather complicated!

Let's dive into it. Image
1/8

Every time a Pod is created, it also added to the Scheduler queue.

The scheduler process Pods 1 by 1 through two phases:

1. Scheduling phase (what node should I pick?)
2. Binding phase (let's write to the database that this pod belongs to that node) ImageImageImageImage
2/8

The Scheduler phase is divided into two parts. The Scheduler:

1. Filters relevant nodes (using a list of functions call predicates)
2. Ranks the remaining nodes (using a list of functions called priorities)

Let's make an example.
Read 9 tweets
26 Aug
MEGATHREAD

Learn Kubernetes one Twitter thread at the time!

Below you can find a collection of threads about Kubernetes and Kubernetes-related tech!

I regularly add more, so you can follow me or @learnk8s for more updates!
What happens when you create a Pod in Kubernetes?

In this thread, you will learn how endpoints are propagated in the cluster when a Pod is created!

In Kubernetes, what should I use as CPU requests and limits?

Learn how to set requests and limits on your Pods.

Read 12 tweets
6 Aug
THREAD: What happens when you create a Pod in Kubernetes?

Spoiler: a surprisingly simple task reveals a complicated workflow that touches several components in the cluster.
1/8

You are probably familiar with the first 4 steps:

1. kubectl sends the YAML to the API
2. The Pod is stored in etcd
3. The scheduler assigns a Node

At this point the Pod is etcd, but no in the node.

4. The kubelet starts creating the Pod.
2/8

Next:

1. The kubelet delegates creating the container to the CRI
2. The kubelet delegates attaching the container to the network to the CNI
3. The CNI assigns an IP address
4. Probes are checked
5. The kubelet reports the IP address to the control plane
Read 9 tweets
29 Jul
THREAD: What is GitOps?

Is this something that you should learn?

Let's dive into it.
1/10

The idea behind GitOps is straightforward:

1. Scripts that create update, delete, etc. infrastructure are saved in GIT.
2. The state of your infrastructure is saved in GIT.
3. You have automation to trigger all your scripts.

Let's see an example.
2/10

Let's deploy an app with a single replica:

1. Commit the Deployment definition in GIT
2. Execute the script to deploy
3. Done

How is this new?

Surely you do this already!

The devil is in the details, though.
Read 11 tweets
22 Jul
THREAD: Is it possible that Kubeflow pipeline is one of the best CI/CD tools for Kubernetes?

I spent some time playing with Kubernetes & @kubeflow pipelines, and they have one feature which is just great:

You can define the pipeline with real code!
1/7

Kubeflow Pipelines is a CI/CD tool for machine learning.

Every step of the pipeline runs in a container — just like other CI/CD tools (Drone, Jenkins X, etc.)
2/7

But instead of writing YAML to define the steps, you can use a real programming language!

You can use Python to write the code and then submit it to Kubeflow.

If you prefer, you can still use YAML to define the pipeline.
Read 8 tweets
14 Jul
THREAD: How does the Kubernetes API work?

The Kubernetes API is made of several smaller components.

In this thread you will learn about the component involved in storing resources into etcd.
1/10

When you type 𝚔𝚞𝚋𝚎𝚌𝚝𝚕 𝚊𝚙𝚙𝚕𝚢 -𝚏 𝚖𝚢.𝚢𝚊𝚖𝚕 your YAML is sent to the API and stored in etcd.

𝘉𝘶𝘵 𝘸𝘩𝘢𝘵 𝘪𝘴 𝘵𝘩𝘦 𝘈𝘗𝘐 𝘥𝘰𝘪𝘯𝘨?
2/10

The API has a single block in the diagram, but the reality is that several components are involved in processing your request.

The first component in the API is the HTTP handler.

You can think about it a web server ready to receive HTTP requests:
Read 11 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!