Sobes.tech
Middle+

Describe in detail what happens after executing the command kubectl apply -f deployment.yaml — in what order and on which cluster components.

sobes.tech AI

Answer from AI

After executing the command kubectl apply -f deployment.yaml, the following process occurs:

  1. kubectl reads the deployment.yaml file and sends its contents to the Kubernetes API server via REST API.

  2. The API server receives the request and validates the manifest: checks syntax, schema, and user permissions.

  3. If a resource (Deployment) with the same name already exists, the API server compares the current configuration with the new one and applies changes (patch). If not, it creates a new object.

  4. The updated Deployment object is saved in etcd — the distributed cluster state storage.

  5. The Deployment controller (running in the controller manager) detects changes in the Deployment object through watch on the API server.

  6. The Deployment controller creates or updates the corresponding ReplicaSet and manages the number of pods to match the desired state.

  7. The ReplicaSet controller creates or deletes pods to maintain the required number of replicas.

  8. The Kubelet on nodes receives instructions to launch new pods and runs containers via the container runtime.

  9. The state of pods and containers is updated and reflected in the API server, allowing kubectl to display current information.

Thus, the command initiates a chain of interactions between kubectl, the API server, etcd, controllers, and kubelet to bring the cluster state in line with the manifest.