Kubernetes Resource Model (KRM) and How to Make Use of YAML?
Last Updated :
30 Mar, 2023
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:
- Humans can readily understand them. YAML files are flexible and expressive.
- They're simple to set up and operate.
- They are easily transferable from one programming language to another.
- They are compatible with agile languages' inherent data structures.
- To facilitate generic tools, YAML files have a consistent model.
- They are capable of one-pass processing.
- They're simple to use, so you won't have to type in all of your arguments on the command line.
- You can do maintenance. To track changes, YAML files may be added to source control.
- 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 YAMLKubernetes 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:
- ownerReference (UID)
- Selector
- 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 Deployment2. 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.
Similar Reads
Kubernetes Tutorial Kubernetes is an open-source container management platform that automates the deployment, management, and scaling of container-based applications in different kinds of environments like physical, virtual, and cloud-native computing foundations. In this Kubernetes Tutorial, you are going to learn all
8 min read
Introduction to Kubernetes
Installation and Setup
Application Deployment
What are Kubernetes Containers?Kubernetes is an open-source container orchestration framework that was originally developed by Google. Container orchestration is automation. It can facilitate you to deploy the identical application across different environments like physical machines, virtual machines cloud environments, or perha
15 min read
Kubernetes - Introduction to Container OrchestrationIn this article, we will look into Container Orchestration in Kubernetes. But first, let's explore the trends that gave rise to containers, the need for container orchestration, and how that it has created the space for Kubernetes to rise to dominance and growth. The growth of technology into every
4 min read
Kubernetes - ImagesPre-requisite:- Kubernetes A container image is used to represent binary data that is being used to encapsulate an application and all its software dependencies. Container images can be represented as executable software bundles that run standalone and make very defined assumptions about their runti
3 min read
Kubernetes - JobsPre-requisite: Kubernetes In the Kubernetes world, jobs are considered an object to act as a supervisor or controllers of a task. The Kubernetes job will create a pod, monitor the task, and recreate another one if that pod fails for some reason. Upon completion of the task, it will terminate the pod
4 min read
Kubernetes - Labels & SelectorsAn open-source container management platform called Kubernetes automates the deployment, scaling, descaling, and load balancing of containers (also called a container orchestration tool). It was created by Google in Golang and has a sizable community as a result of that. Google eventually donated it
5 min read
Kubernetes - NamespacesKubernetes Namespace is a mechanism that enables you to organize resources. It is like a virtual cluster inside the cluster. A namespace isolates the resources from the resources of other namespaces. For example, You need to have different names for deployments/services in a namespace but you can ha
9 min read
Kubernetes - NodeKubernetes Nodes are the Worker or master machines where the actual work happens. Each Kubernetes node has the services required to execute Pods and is controlled by the Control Plane. Each Kubernetes Node can have multiple pods and pods have containers running inside them. 3 processes in every Node
13 min read
Kubernetes - NodePort ServiceNodePort service in Kubernetes is a service that is used to expose the application to the internet from where the end-users can access it. If you create a NodePort Service Kubernetes will assign the port within the range of (30000-32767). The application can be accessed by end-users using the node's
5 min read
Kubernetes - ClusterIP vs NodePort vs LoadBalancerThree main service types are used in Kubernetes networking: ClusterIP, NodePort, and LoadBalancer. Each has a specific function in controlling external access and service-to-service communication. Comprehending their distinctions is essential for efficiently coordinating applications. This article e
7 min read
Kubernetes - ServicesSoftware deployment, scaling, and management are all automated using Kubernetes, an open-source container orchestration system. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computing Foundation. Despite the fact that it now s
3 min read
Kubernetes Pods: How to Create and Manage ThemKubernetes is an open-source container orchestration system mainly used for automated software deployment, management, and scaling. Kubernetes is also known as K8s. Kubernetes was originally developed by Google, but it is now being maintained by the Cloud Native Computing Foundation. It was original
13 min read
How to Run Shell Commands in Kubernetes Pods or ContainersIn Kubernetes, we create pods by adding an extra layer of information on containers. This Kubernetes in short is known as K8s, an open-source container orchestration tool developed by Google. It is used to orchestrate the containers for bringing Agility in software deployment through scaling, and ma
6 min read
Kubernetes - Creating Multiple Container in a PodPre-requisite:- Kubernetes Kubernetes is a container management tool and it automates container deployment, load balancing, and container scaling. It is open-source and developed by Google in 2014 and written in Golang. All cloud providers adopt Kubernetes. It is scheduled runs and manages isolated
3 min read
Kubernetes - Replication ControllerWith the help of the open-source container orchestration technology Kubernetes, software deployment, scalability, and management are mostly automated. Another name for Kubernetes is K8s. Google created Kubernetes, which is now overseen by the Cloud Native Computing Foundation. Even though it now wor
7 min read
Kuberneters - Difference Between Replicaset and Replication ControllerPre-requisite: Kubernetes Kubernetes is also known as K8s is an open-source container orchestration tool developed by google which is used for automating software deployment, scaling, and management. Currently, it is being maintained by the cloud native computing foundation(CNCF). K8s has two versio
4 min read
What is Kubernetes Deployment?Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, descaling, and container load balancing (also called as container orchestration tool). It is written in Golang and has a huge community because it was first developed by Google and later do
10 min read
Configmaps
Kubernetes - ConfigMapsKubernetes allows you to run and manage applications in containers. However, when you need to update configurations like usernames, passwords, or URLs without modifying the application code, ConfigMaps provide an efficient solution. ConfigMaps separate application configuration from the application
10 min read
Kubernetes - Create Config Map From FilesPre-requisite: Kubernetes While creating a manifest file in Kubernetes, we can define environment variables. However, when you have a lot of manifest files, it will become difficult to manage the environment data stored in various manifest files. To overcome this issue, we can manage environment dat
3 min read
Kubernetes - Create ConfigMap From YAML FileA 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
1 min read
Kubernetes - Config Map From DirectoryPre-requisite:- Kubernetes Software deployment, scalability, and administration are mostly automated using Kubernetes, an open-source container orchestration framework. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computing F
2 min read
Kubernetes - Injecting ConfigMap as FilesPre-requisite:- Kubernetes The automated deployment, scaling, and administration of software using a system called Kubernetes, an open-source container orchestration tool. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computin
3 min read
Kubernetes - Injecting ConfigMap in PodsPre-requisite: Kubernetes Leveraging the open-source container orchestration engine Kubernetes to automate the deployment, scalability, and management of applications. Another name for Kubernetes is K8s. Google originally created Kubernetes, which is currently overseen by the Cloud Native Computing
3 min read
Scaling and Updating Applications
Kubernetes - Service DNS An open-source container orchestration system called Kubernetes is primarily employed for the automated deployment, scaling, and management of software. Another name for Kubernetes is K8s. Initially created by Google, Kubernetes is currently maintained by the Cloud Native Computing Foundation. Altho
11 min read
Additional Topics
What is Kubernetes API ?Complete GuideKubernetes API is an application that serves Kubernetes functionality through a RESTful interface and stores the state of the cluster via HTTP. Users can directly interact with the Kubernetes API or via tools like kubectl. It supports retrieving, creating, updating, and deleting primary resources vi
14 min read
Kubernetes - Taint and TolerationA 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 clou
6 min read
Kubernetes Resource Model (KRM) and How to Make Use of YAML?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-CodeAccording to Kubernetes co-founder Brian Grant, Kubernetes is very convenient thanks to the Kubernetes R
6 min read
Installing Private Git Server on K8s Cluster with Gitea and AKSIn this article, we are going to install a self-hosted Gitea server on top of Azure Kubernetes Service with Helm and set up a git repo. Having a private Git server might be beneficial these days. Gitea is a community-managed Git-compatible lightweight code hosting solution written in Go. It is publi
4 min read
Enable Remote Debugging For Java Application Deployed in Kubernetes EnvironmentDuring Development, developers have to debug their applications to resolve code problems. In order to debug a java application which is deployed on remote machine in a Kubernetes cluster, first developer has to do some steps to enable its application ready for debugging. Below are the manual steps t
2 min read
How to Enable JMX For Java Application Running in the Kubernetes Cluster?Many times we want to monitor our application's CPU utilization, background thread behavior, and most importantly memory consumptions for tasks that deal with loads for data (500MB - 1GB) or much more data. Such monitoring helps to find which operation is causing heavy CPU or Memory utilization and
3 min read