The Wayback Machine - https://web.archive.org/web/20240627171307/https://www.geeksforgeeks.org/kubernetes-resource-model-krm-and-how-to-make-use-of-yaml/
Open In App

Kubernetes Resource Model (KRM) and How to Make Use of YAML?

Last Updated : 30 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Here we will explain how YAML can simplify system management and automation of most processes so that Kubernetes is a convenient working system.

Basic Kubernetes Models: KRM and Everything-as-Code

According to Kubernetes co-founder Brian Grant, Kubernetes is very convenient thanks to the Kubernetes Resource Model (KRM) resource model. This is a way to create a declarative configuration file in a readable format to define the desired system state using code. A key aspect of KRM is the uniform declarative metadata. Therefore, KRM is often expressed as YAML and declares the basic idea that everything in Kubernetes is YAML.

A similar idea underlies the Everything-as-Code paradigm (EaC, all as code). According to its principles, the entire IT infrastructure can be configured with code from configuration to security systems. This makes it declarative, which allows you to focus not on implementing individual functions but on the final goals and states. Nevertheless, YAML is important to have a better balance in using these technologies flawlessly. 

Kubernetes and YAML

Kubernetes is called the 21st century Linux kernel. This idea compares the ability to search for any information about the system through proc in Linux and through the API in Kubernetes: first – all files (file streams), second – all YAML. You can get information about any parts of the system and applications implemented in the form of Kubernetes operators and custom resources. Using YAML dramatically simplifies these tasks.

In fact, thousands of projects – from CNI(Container Network Interface) and ServiceMeshs to Security and Infrastructure – are native to Kubernetes in the form of Kubernetes operators and custom Kubernetes resources. Cilium, Istio, Gloo, Knative, ClickHouse, and other services can be managed and monitored natively by simply changing and tracking YAML files. This confirms that Kubernetes and YAML are closely related and interdependent.  

Here is a list of pros to using YAML files:

  1. Humans can readily understand them. YAML files are flexible and expressive.
  2. They’re simple to set up and operate.
  3. They are easily transferable from one programming language to another.
  4. They are compatible with agile languages’ inherent data structures.
  5. To facilitate generic tools, YAML files have a consistent model.
  6. They are capable of one-pass processing.
  7. They’re simple to use, so you won’t have to type in all of your arguments on the command line.
  8. You can do maintenance. To track changes, YAML files may be added to source control.
  9. They are adaptable. YAML allows you to design more complicated structures than you can on the command line.

Why it is essential to have the same type ensured by using YAML?

The same type of implementation was always necessary, and its importance only increases with the popularization of the DevSecOps-approach(Developer Security Operations). Now many different commands can work with the cluster, and each of them should be able to see the overall picture of what is happening and clearly understand it. This is essential for the timely implementation of mandated tasks and the coherence of all departments.

If the exact implementation is not ensured, it is easy to have specialists from different departments see only fragments of information about services and infrastructure without any coordination. This complicates both everyday work and debugging. Such cases are unacceptable – all should equally see what is happening in the infrastructure.

Real-Life Example:

Let’s suppose, the development team, operation, has been solving the problem for a long time: for some reason, in one particular environment, the application worked normally on the network(environment), and in another, it did not work. 
One image, one setup, all completely identical, but something is wrong. After a few hours, they despaired and went to the security team. It turned out that the development team/operation team used a third-party commercial solution, which for its work introduces third-party libraries into processes running in containers. And these processes blocked what they thought was the wrong behavior. The lock could only be seen inside the process memory and directly in the interface, which only the security command has.

Now one question arises i.e.”if something does not work in the infrastructure, you need to go to security, and then understand?“. Basically, we shouldn’t be practicing that in real-life to go to the security guards with any problem. Everything that happens in infrastructure should be equally transparent to everyone.

Same Type by YAML

Same Type by YAML

Kubernetes is a framework. It is designed to be as flexible as possible to create infrastructure for its teams and processes, in this case, not only the infrastructure associated with high availability, directly with the rapid expansion of services, but also with all aspects related to databases serviceless-loads, security, and others.

YAML is a «friendly» format of serialization(converting one form to another). It is not only simple syntax and allows you to store data in a compact and readable form, but also suitable for all programming languages. This allows you to use it to ensure the same type of design is understandable and convenient for all devs.

Kubernetes can be much more complicated than you think

In most Source-code managers (SCM) used by companies, projects are placed in several ways:

  • YAML resources are provided by service.
  • YAML resources are placed according to the name of the service and its type: Deployment, Service, Ingress, and so on.
  • Resources are stored by category and subcategory.

So, resources are tied. And connections are essential for supporting and understanding the device of the services and other entities of the cluster, as is the lack of communication – it can point to typos and errors. But this requires maintaining and understanding a vast array of different projects with their linkage logic.

Example:

kubectl -n namespace get all

Kubernetes, provide the following command. From its description, it seems that it will return all the resources in this namespace. 
But that’s not true: the team sees only a particular set of resources. Therefore, you will get a partial idea of the specified namespace if you use it.

How to Link Resources?

There are 3 highlighted ways of linking resources – they will be useful if you will understand someone else’s project or write your Kubernetes operator with your custom resources:

  1. ownerReference (UID)
  2. Selector
  3. targetRef

1. ownerReference

Allows one resource to refer to its «parent» In this way, the change or removal of the «parent» affects all descendants. This option is used, for example, when Deployment – «parent» ReplicaSet, and ReplicaSet – «parent» pod.

ownerReference actively uses GarbageCollector: if a parent is deleted, all resources associated with it on ownerReference will be deleted. For more understanding, removing an image for a container in a descriptive model will also delete the resource that stores the associated scan results and reports.

ownerReference Deployment

ownerReference Deployment

2. Selector

The most common way to link resources among themselves – is by selectors and labels

Key/value pairs called labels are stuck/attached to things like pods. Although labels are not designed to explicitly suggest semantics to the main system, they are intended to be used to indicate distinguishing qualities of objects that are meaningful and important to users.

3. targetRef

One way to organize communication is targetRef. It implies specifying the API version of the resource, its name, and the resource type.

This way gives a clear understanding of all the relationships, so targeted (name may vary depending on the implementation, but the idea remains the same) is considered best for linking resources to each other.



Previous Article
Next Article

Similar Reads

Kubernetes - Create ConfigMap From YAML File
A ConfigMap is a dictionary consisting of non-confidential data. Its primary role is to keep the configuration separate from the container image. ConfigMap can be created in different ways. This article will cover the declarative approach to creating ConfigMap from the YAML file. Example: apiVersion: This specifies which version of Kubernetes API w
1 min read
What Is YAML In Kubernetes ?
Kubernetes is dependent on YAML (YAML Ain't Markup Language) as its configuration language. YAML makes managing and deploying Kubernetes more easy and simple. In this article, we'll cover all the aspects of using YAML in Kubernetes. Understanding YAMLYAML is a human-readable format of data serialization. In Kubernetes, YAML files are used to define
7 min read
Kubernetes - Monolithic Architecture of Kubernetes
There is a new way of developing software apps using a microservices architecture. That's when all the buzz around containers and container orchestration has increased but we have been developing and using these large software apps even before most of us were born. So in this article, we will be discussing what is that old software architecture we
7 min read
Why Kubernetes? Benefits of using Kubernetes
The popularity of container orchestration technologies specially Kubernetes comes from its use cases and the problems that it solves. Kubernetes is the most popular container orchestration and is widely used by Cloud Native Computing Foundation (CNCF), the foundation to which Kubernetes as a project was donated by Google, estimates that about 92% b
8 min read
Kubernetes Controller VS Kubernetes Operator
Kubernetes Controllers are ideal for managing stateless apps and maintaining the correct number of copies, but Kubernetes Operators are more appropriate for complicated, stateful applications that require human-like decision-making abilities. Kubernetes ControllerKubernetes Controllers are ideal for managing stateless apps and maintaining the corre
4 min read
What is the alternative to YAML and JSON?
YAML (YAML Ain't Markup Language) and JSON (JavaScript Object Notation) have been enduring choices for data serialization, valued for their simplicity and readability. Despite their prominence, the world of data serialization formats is diverse, providing alternatives tailored to specific requirements or preferences. Selecting the Appropriate Alter
5 min read
What does {{ }} mean in YAML?
YAML (YAML Ain't Markup Language) is a popular human-readable data serialization format often used for configuration files and data exchange. YAML's simplicity and readability have made it a favorite among developers and system administrators. While YAML is generally straightforward, there are times when you encounter unfamiliar constructs, such as
5 min read
Convert YAML to JSON
YAML (YAML Ain't Markup Language) and JSON (JavaScript Object Notation) are both popular data serialization formats. Both these formats are used to represent the data in various scenarios, We can convert the YAML to JSON format by using a mixture of Python Library and Shell Script for automation. We can convert the single YAML file along with a bun
7 min read
What Type of Language is YAML?
As we know the world of technology is filled with various modern and old languages which keep changing from time to time, each one of these languages serves a specific purpose and thus each language is used for performing certain tasks only. But when it comes to the programming language called YAML people sometimes get confused because they have tr
10 min read
How To Escape The Special Character In YAML With Examples ?
YAML (YAML Ain’t Markup Language) is a popular human-readable data serialization format often used for configuration files and data exchange. In YAML, special characters must be properly escaped to ensure they are interpreted correctly. In this article, we will learn, How to escape the special character in YAML. Methods Of Escaping Character Usage
6 min read
Article Tags :