Part: 1, What Happens When You Run `kubectl apply -f pod.yaml`? ??????
Chaitanya Sawant
SDE @ LivLong || CKA | CKAD | KCNA || 3× Kubernetes Certified || Docker || NextJs || Remixjs || Nodejs || Typescript
If you're working with Kubernetes, you've likely used the kubectl apply command to create resources from a YAML file. But have you ever wondered what happens behind the scenes? Let’s break it down! ??
When you run kubectl apply -f pod.yaml, the Kubernetes client first validates the YAML file syntax. It ensures that the resource definitions match the expected API schema. If everything is correct, it sends an HTTP request to the Kubernetes API server with the resource specifications.
2. Authentication & Authorization ??
The API server authenticates the request using configured identity mechanisms (such as certificates or tokens) and checks if the user has permission to perform the requested action (based on RBAC rules). If authorized, it moves to the next step.
3. Admission Controllers ?
Before making any changes to the cluster, the API server runs the request through Admission Controllers. These controllers enforce policies like pod security, resource limits, or mutating webhook rules. They may modify or reject the request based on set policies.
4. Persisting to etcd ???
Once the request passes all checks, the API server stores the pod specification in etcd, the distributed key-value store that holds all cluster data. This makes the pod part of the cluster’s desired state.
5. Scheduler in Action ??
领英推荐
With the pod registered, the Kube-Scheduler takes over. It examines the pod’s resource requirements and affinity/anti-affinity rules and selects the most suitable node to run the pod. The scheduler updates the pod object with the node assignment.
6. Kubelet and Pod Creation ??
After scheduling, the Kubelet on the selected node picks up the task. It communicates with the Container Runtime (like Docker or containerd) to pull necessary container images and create the containers. The Kubelet monitors the pod's status and ensures it’s running as expected.
7. Continuous Monitoring ??
Throughout the pod’s lifecycle, the Kubelet constantly reports the pod’s status back to the API server. Tools like kubectl get pods allow you to track the pod’s status in real-time. If something goes wrong, Kubernetes works to reconcile the actual state with the desired state!
In short this happens:
I'll explain each step in detail in other parts so stay tuned. If you have any doubts comment them.
Software Engineer @Livlong 365
4 个月Useful tips
Principal Engineer specializing in Full Stack Development at Livlong
4 个月Great explanation
Software Engineer @Livlong 365 | DS & ML Enthusiast | VESIT'24
4 个月Very helpful, thanks for sharing