Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

KubernetesCloud / DevSecOps series

What happens when you run kubectl apply

You run kubectl apply -f app.yaml and a pod appears. Between those two moments, the control plane does a precise sequence of work. Understanding it explains why Kubernetes is declarative, and where to look when a pod never starts.

Quick reference

TimeStepWhat happens
1kubectl sends itYour YAML goes to the API server, authenticated.
2Validated and storedThe API server checks it and writes it to etcd.
3Controller noticesThe deployment controller sees the desired state.
4Scheduler picks a nodeIt chooses where the new pod should run.
5kubelet starts itThe node's agent pulls the image and runs the container.
6Status flows backHealth is reported up to etcd. kubectl get shows Running.

Explained

  1. kubectl sends it. Your YAML is sent to the API server as a request, authenticated with your kubeconfig credentials and checked against RBAC. kubectl itself does not create anything; it just talks to the API server.
  1. Validated and stored. The API server validates the object (is the YAML well-formed, do the fields exist, are you allowed?) and writes the desired state into etcd. At this point the object exists in the cluster's brain, but nothing is running yet.
  1. Controller notices. The relevant controller, for a Deployment that is the deployment controller, is watching for changes. It sees the new desired state and creates the objects below it, a ReplicaSet, which in turn wants pods.
  1. Scheduler picks a node. The new pods have no node assigned. The scheduler evaluates resources, taints, affinity and constraints, and binds each pod to a suitable node. A pod stuck in Pending usually means this step could not find a fit.
  1. kubelet starts it. The kubelet on the chosen node sees a pod assigned to it, tells the container runtime to pull the image and start the container, and runs the probes.
  1. Status flows back. The kubelet reports health up through the API server into etcd, and kubectl get pods shows Running.

The whole idea: you declare the goal, and independent controllers continuously converge reality toward it.

In one line

You declare. The cluster converges. apply sets the goal; controllers make it real.

Watch it happen

kubectl get pods -w

More notes: Kubernetes

Open in the notes app: search, filters, copy This note on GitHub