Part 2: What Happens in the Control Plane When You Run kubectl apply -f pod.yaml???????
Chaitanya Sawant
SDE @ LivLong || CKA | CKAD | KCNA || 3x Kubernetes Certified || Docker || Git || NextJs || Remixjs || Nodejs || Typescript
When you run the command kubectl apply -f pod.yaml, a series of operations take place within the Kubernetes control plane to ensure that the desired state (defined in the pod.yaml file) is reached in the cluster. The control plane, which is composed of multiple components, orchestrates these operations and manages the lifecycle of the resources.
Here is a detailed breakdown of the entire process, focusing on the actions that happen within the control plane:
1. Kubectl Client-Side Processing
Before any action happens in the control plane, the kubectl command processes the provided file (pod.yaml) on the client-side:
Once this request is created, it is sent to the API server, which is the entry point to the Kubernetes control plane.
2. Kubernetes API Server (kube-apiserver)
The API server is the heart of the control plane. It receives and processes all requests to manage and interact with the cluster. Here's what happens when the kubectl apply request arrives:
a) Authentication
The API server first checks who made the request. It performs authentication by verifying the credentials (certificates, tokens, etc.) of the user or service account that initiated the request.
b) Authorization
Once authenticated, the API server checks whether the user is authorized to perform the requested action. Kubernetes uses Role-Based Access Control (RBAC) to define who can perform which actions on which resources.
c) Admission Controllers
Admission controllers are plugins that intercept the request before it is persisted. They apply policies to regulate resource creation, enforce quotas, mutate resources, or add additional defaults. Admission controllers can modify the object or deny the request based on their configuration. Common types include:
d) Persisting to etcd
Once all validations, authorizations, and admission controller processes are complete, the desired state (in this case, the Pod definition) is stored in etcd, the cluster's key-value store. etcd acts as the source of truth for the cluster's state, recording the intended state of all resources.
When the Pod specification is written into etcd, it becomes part of the cluster’s desired state.
领英推荐
3. Controller Manager (kube-controller-manager)
After the API server has successfully persisted the Pod definition into etcd, the Controller Manager kicks into action. It constantly watches for changes in the desired state stored in etcd and compares them to the current state of the cluster.
The Controller Manager contains several controllers, and in this case, the Pod Controller and ReplicaSet Controller are particularly relevant:
a) Pod Controller
b) ReplicaSet Controller
c) Node Assignment
4. Kubernetes Scheduler (kube-scheduler)
Once the Pod is marked for scheduling, the Scheduler is responsible for assigning it to a suitable node. The Scheduler's job is to find the best available node to run the Pod based on a number of factors:
a) Node Filtering
The Scheduler starts by filtering out nodes that do not meet the Pod's requirements, including:
b) Node Scoring
Once nodes are filtered, the Scheduler scores the remaining nodes based on additional factors such as resource utilization, topology, and policies. The Scheduler selects the node with the highest score and assigns the Pod to it.
c) Updating the Pod Object
After making its decision, the Scheduler updates the Pod object in etcd, specifying which node the Pod is assigned to.
Summary of Control Plane Operations:
Once this is done Data Plane comes in picture which will be explained in next post.
Principal Engineer specializing in Full Stack Development at Livlong
5 个月Thanks for sharing this, it's a good read