what happens background when you fire command Kubectl apply?

8/11/2021

When we fire command Kubectl apply -f <file.yaml>, what happens in background?

-- Mahesh
kubernetes

1 Answer

8/11/2021

In a nutshell, Kubernetes works by having a bunch of "object" or "resource" definitions (like Deployments, ConfigMaps and such), and continuously trying to match the state of the system to these definitions.

For example, if there is a Deployment definition, but there is no pod running for that, K8s will keep trying to spin up such a pod. This might fail due to many reasons - there might not be a node with enough free resources available, the image might not be found, and so on, but as soon as all obstacles are cleared, it will start the pod without further action from you.

kubectl apply -f file.yaml then simply reads the content of that file and adds it to its internal store of definitions (where "add" can mean a complex situation if there are overwrites, merges or deletions involved; see the man kubectl-apply documentation for details).

-- AnoE
Source: StackOverflow