Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Kubernetes work?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

What is the working principle of Kubernetes? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

1. Kubernetes Core component Analysis 1.1 Core concept: Pod

Pod is the smallest deployable computing unit in Kubernetes

Such a set of containers are "packaged" together to form a Pod and accept Kubernetes scheduling, orchestration and other control logic.

In order to better understand the concept of "a set of containers", the next step is to analyze the internal structure of Pod in detail.

The internal architecture of Pod

The blue part represents the entire Pod. The net namespace in the upper right corner is the Pod-level namespace, which represents all the containers in the Pod.

There are four Container (i.e. PauseContainer/Container A/Container B/Container C /) in the figure, all of which are added to the namespace when they are created.

So where does Pod-level Container come from? As you can see from the picture, we label the real working Container as A _ Magi B ~ C. Pause Container acts as a placeholder. When we create a Pod, we first create a Pause Container. The namespace created by this container is equivalent to the namespace of the entire Pod.

Of course, not all namespace are not isolated. To the left of the Container is an image, each container has an image, and each image is equivalent to the Root ffs of a container. Since the Root ffs of each container is different, it is obvious that the mnt namespace is isolated.

This allows us to clearly see which namespce are isolated from each other in Pod and which are shared at the Pod level.

The presentation form of Pod in Kubernetes

In general, we are used to using Yaml to describe resources in Kubernetes. The content in Yaml is actually our description of resource parameters.

Let's first look at the first four lines of Pod in Yaml. These four lines are common fields for resources in Yaml. ApiVersion/kind is used to indicate what the resource type of Kubernetes is. Declare the source data of the resource through metadata. The Spec field is strongly related to the resource type. Different resources have different spec definitions. Among the Pod resources, the core is the definition of containers.

The following lines, regarding the definition of a container, are of an array type, which also fits our definition of Pod: that is, it is formed by a set of containers. These fields include: declare the container image, the command to start the container, how to pull the container image, and the name of the container.

1.2 Core Concepts Kubelet

Kubelet is the "node agent" of the Kubernetes cluster. It can also be said that Kubernetes is deployed in the agent of each node.

After Kubelet starts, it registers itself with the Kubernetes cluster and reports the relevant information of the node. At this point, a new available Node node (either a physical machine, a virtual machine, or even a container) is added to the Kubernetes cluster.

When Kubelet discovers that the Pod of its own node meets the creation conditions, it will start the container according to the configuration declared by Pod.

1.3 related components of the Kubernetes control plane

The above picture is divided into three parts:

1. The second half: the Kubelet/Pod introduced earlier.

two。 Upper left corner: Kubectl. That is, Kubernetes's command line tool. You can submit the Yaml of the resource to the Kubernetes cluster through Kubectl. It can also carry out a series of operation and maintenance operations.

3. On the right: the Master node. That is, the relevant components of the Kubernetes control plane. Where API Sever is the integration entry for all source data in Kubernetes. It is also the central component of the entire Kubernetes cluster. Other components (including Controller, Scheduler, etc.) need to deal with API Sever when getting data. API Sever also accepts requests for co-entry from these components and eventually writes the data to the ETCD. At the same time, API Sever caches all source data. When other components make a "read" request, they send the data directly from memory to each other. Try to avoid ETCD becoming the bottleneck of the system. In addition to the source data storage function, API Server also provides a Watch mechanism. Be able to actively push the change of a certain resource. Scheduler registers with API Sever and listens to Pod for resource change events. The overall scheduling logic of Scheduler can be simplified and summarized into two: filtering and scoring.

After filtering, we get a list of Node that meets the requirements, and Scheduler will calculate the score of each Node through the scoring algorithm. Finally, the node with the highest score is selected as the node that Pod needs to bind. Eventually, Scheduler will write back the result to API Sever.

Choreography component: Controller. Controller uses several fixed workload. Through the way of the controller to complete the run-time server orchestration work.

two。 Quick build Kubernetes Cluster 2.1Builder: introduction to Kubeadm

Kubeadm is a tool officially provided by Kubernetes for quick installation of Kubernetes clusters.

The following figure shows the configuration file for Kubeadm

In the configuration file, we specify the type of dns, the ETCD storage directory, the version of the Kubernetes to be created, and related parameters.

2.2 build the environment

Initial Master node

Kubeadm init-config kubeadm.conf

Install flannel cni

Https://raw.githusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

3. Demo: demonstrate how to operate a Pod

Create a Namespace

Kubectl create namespace demo

Create Pod

Kubectl apply-f pod.yaml

View Pod running status

Kubectl describe pods demo-pod-n demo

View Pod output log

Kubectl logs demo-pod-n demo

View Pods list

Kubectl get pods-n demo

Delete Pod

Kubectl delete-f pod.yaml

MoreCommand

Basic Commands: create,expose, run, setBasic Commands: explain, get,edit,deleteDeploy Commands: rollout,scale,autoscale after reading the above, have you mastered how Kubernetes works? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report