The Wayback Machine - https://web.archive.org/web/20240906223420/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
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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
Understanding YAML Tags and Data Typing What exactly does `ssh-keygen -A` do?
We have adopted a popular data serialization format called YAML (YAML Ain't Markup Language) in file configuration and data interchange. Its primary focus is on human readability while supporting the feature of data typing. Let's break down these two ideas: YAML TagsOne of the features that YAML provides is tags, which are used as optional markers
6 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
Fixing Sequence Items Not Allowed Error in YAML
The YAML is a readable data serialization standard commonly used for configuration files and data exchange formats. Errors such as "Sequence Items are not allowed here" often occur due to the syntax issues in the YAML files. This article guides us through the steps to identify and correct this specific error. Understanding the ErrorThe error messag
4 min read
How to Install and Use BpyTop Resource Monitoring Tool in Linux?
It's just as critical for terminal users to be able to keep track of their system's resource use. Knowing how much of your system's resources are being used allows you to make more educated decisions about general system maintenance. Top and htop are two choices, but they only show a few device metrics including CPU and memory use. Bpytop is a term
2 min read
How To Use Kubernetes Taints and Tolerations?
Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, descaling, and container load balancing (also called a container orchestration tool). Suppose there is a scenario, you have a single cluster where you run all of your production, staging, and testing workloads. Our Productions nodes are of
5 min read
How To Use Kubernetes Liveness and Readiness Probes?
Kubernetes (also known as K8s) is an open-source Container Management tool. It helps us automate all the processes like deployment, load balancing, rolling updates, etc. We can deploy, scale, and manage containerized applications. Table of Content What are Kubernetes Liveness and Readiness Probes?What are the Three Types of Kubernetes Probes?How Do
15 min read
How to Use Kubernetes Annotations?
Annotations are key-value pairs that are used to attach non-identifying metadata to Kubernetes objects. Various tools that are built over Kubernetes use this metadata attached by annotations to perform actions or enhance resource management. Labels and Annotations are used to attach metadata to Kubernetes objects. This makes annotations important f
11 min read
How To Use Docker Desktop To Deploy Kubernetes Clusters ?
Docker Desktop has revolutionized local development environments by seamlessly integrating Kubernetes, a powerful container orchestration platform. This article gives an idea of how to use Docker Desktop to deploy Kubernetes clusters, which also includes step-by-step instructions and troubleshooting advice. This thorough instruction will enable you
6 min read
How To Use Kyverno In Kubernetes ?
The name is Kyverno comes from the Greek word Kyverno, which means "to govern". Kyverno is a Policy Engine designed specifically for Kubernetes that is Kubernetes Native (i.e. it uses Kubernetes resources, patterns, and idioms) and enables the users to manage security and best practices in their Kubernetes Clusters. In this article, we will discuss
11 min read
How To Use Azure Kubernetes Service For Container Orchestration ?
Azure Kubernetes Service provides a platform for managing containers with the help of Kubernetes. It also provides an easy and managed way for the deployment and scaling of containerized applications. Containerized applications are deployed in the Kubernetes cluster in Azure. Let's see how to use the Azure Kubernetes Service for deploying container
4 min read
How To Use Kind To Deploy Kubernetes Clusters?
Kind also referred to as Kubernetes in Docker is a popular open-source tool used for running a Kubernetes cluster locally. Kind uses Docker containers as Cluster Nodes making it substantially faster than its alternatives like Minikube or Docker Desktop which uses a Virtual Machine. Kind is commonly used to test Kubernetes clusters on local machines
10 min read
How To Use Kubernetes Secrets As Files In Containers ?
Secrets are Objects in Kubernetes that are used to store the data and credentials that we would not want to share with others. Secret is a Kubernetes component just like Configmap but the difference is that it's used to store secret data credentials and it stores this data not a plain text format but in base64 encoded format. In this article, we wi
8 min read
How to use Kubernetes Statefulsets?
StatefulSets are API objects in Kubernetes that are used to manage stateful applications. There are two types of applications in Kubernetes, Stateful applications and stateless applications. There are two ways to deploy these applications: Deployment (for stateless applications)StatefulSets (for stateful applications)What are Stateful Applications?
10 min read
How to Use Kubernetes Horizontal Pod Autoscaler?
The process of automatically scaling in and scaling out of resources is called Autoscaling. There are three different types of autoscalers in Kubernetes: cluster autoscalers, horizontal pod autoscalers, and vertical pod autoscalers. In this article, we're going to see Horizontal Pod Autoscaler. Application running workload can be scaled manually by
10 min read
Linux Virtualization : Resource throttling using cgroups
In Linux Virtualization – Chroot Jail article, we discussed about kernel namespaces and process jailing. To understand this article, you may not need to read the earlier one, but I strongly suggest that you go through it once before diving into resource throttling. It should help tremendously in understanding what's going on. What are cgroups? cgro
9 min read
Custom Resource Definitions (CRDs)
The integrated resources in Kubernetes, such as pods, services, and volumes, provide everyday functions for common-use instances. However, you can not use them on your precise and unique requirements. This is wherein CRDs come into the picture. As the popularity of Kubernetes maintains to grow, so does the need for customizing and extending its com
7 min read
How Raspberry Pi and Kubernetes Work Together?
Pre-requisite: Kubernetes and Raspberry Pi Kubernetes and Raspberry Pi are two popular technologies that can be used together to create powerful and scalable applications. In this article, we will look at what each technology is, how they work together, and the benefits and challenges of using the two technologies together. KubernetesKubernetes is
3 min read
Kubernetes - Taint and Toleration
A pod is a group of one or more containers and is the smallest deployable unit in Kubernetes. A node is a representation of a single machine in a cluster (we can simply view these machines as a set of CPU and RAM). A node can be a virtual machine, a physical machine in a data center hosted on a cloud provider like Azure. When a user runs the below-
6 min read
Benefits and Characteristics of Kubernetes Namespaces
In Kubernetes, Namespaces are used to organize resources. You can have multiple Namespaces in a Cluster And these Namespaces are kind of virtual Clusters of their own. The official definition of Namespace says "In Kubernetes, namespaces provide a mechanism for isolating groups of resources within a single cluster". Within a Kubernetes Namespace, re
7 min read
Kubernetes - Kubectl Create and Kubectl Apply
Kubernetes is an open-source Container Orchestrating software platform that is widely used in modern application deployment and management. It comes up with many internal resources to manage the other working nodes Organizing as a Cluster facilitates seamless automatic scaling, and deployment updates making applications highly available and fault t
8 min read
Difference Between Kubernetes And Elastic Beanstalk
Kubernetes is an open-source container orchestration technology that automates container deployment options have benefits deriving from its structure. Elastic Beanstalk is a Platform as a Service (PaaS) that simplifies application deployment and administration by delivering a fully managed environment.AWS Elastic Beanstalk and Google Kubernetes Eng
5 min read
Article Tags :