123DevOps··6 min read

How does Kubernetes work? From kubectl apply to a running pod

Understand the desired-state model, the control plane and node components, the full path from a Deployment to traffic reaching the pod, plus networking, storage, and self-healing.

Kubernetes

Plenty of people use Kubernetes every day without knowing what happens after kubectl apply. That works until the first pod stuck in Pending or the first Service that doesn’t respond. Understanding the architecture turns those mysteries into concrete questions: which component should have acted, and didn’t?

Desired state and reconciliation loops

Kubernetes is declarative. You don’t say “start three containers”; you record “I want three replicas of this application.” That’s the desired state, stored in each object’s spec field. What actually exists is the actual state, reflected in the status field.

Dozens of controllers run in loops: they watch objects through the API, compare desired with actual, and act to close the gap. Nobody runs a deploy script end to end; each controller owns one piece and reacts to changes. That’s why the system heals itself, and why GitOps fits it so well.

The components

Control plane

Component Role
kube-apiserver The single front door: authenticates, authorizes, validates, and persists objects; every other component talks to it
etcd Distributed key-value store holding all cluster state; only the API server accesses it directly
kube-scheduler Picks which node each new pod will run on
kube-controller-manager Runs the built-in controllers (Deployment, ReplicaSet, Node, Job, EndpointSlice…)
cloud-controller-manager Integrates with the cloud provider: load balancers, routes, and node lifecycle

etcd deserves special attention, because losing its data means losing the cluster. See what is etcd.

Worker nodes

  • kubelet: the agent on every node. It watches the pods assigned to its node, asks the runtime to create them, runs probes, and reports status.
  • kube-proxy: programs network rules (iptables, IPVS, or nftables) so that a Service’s virtual IP reaches its pods. Some network plugins, such as Cilium, can replace it.
  • Container runtime: what actually runs the containers, via the CRI (Container Runtime Interface). The most common are containerd and CRI-O.

What happens on kubectl apply

Consider this Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: shop
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginx:1.27
          ports:
            - containerPort: 80
          readinessProbe:
            httpGet:
              path: /
              port: 80
kubectl apply -f deploy.yaml

The path, step by step:

  1. API server: authenticates the request (certificate, token, OIDC), authorizes it via RBAC, and runs it through the admission controllers: mutating ones first, then schema validation, and finally validating ones (including webhooks and policies).
  2. etcd: the Deployment object is persisted. At this point, no container exists yet.
  3. Deployment controller: notices the new Deployment and creates a ReplicaSet with the pod template.
  4. ReplicaSet controller: sees zero pods against three desired and creates three Pod objects, still without a node assigned.
  5. Scheduler: filters the nodes that can fit each pod (CPU and memory requests, taints, affinities), scores the candidates, and writes the binding, filling in spec.nodeName.
  6. kubelet: on the chosen node, it sees the assigned pod and asks the runtime, via CRI, to create the pod sandbox. The CNI plugin sets up networking and assigns the pod an IP.
  7. Runtime: pulls the image and starts the container. The kubelet reports status back to the API server.
  8. Readiness: once the readiness probe passes, the pod becomes Ready.
  9. Service: the EndpointSlice controller adds the pod’s IP to the endpoints of every Service whose selector matches app: web; kube-proxy updates the rules on each node, and the pod starts receiving traffic.

You can watch much of this live:

kubectl get deploy,rs,pods -n shop -l app=web
kubectl get events -n shop --sort-by=.metadata.creationTimestamp
kubectl get endpointslices -n shop

For more commands like these, see the essential kubectl commands.

The core objects

Object What it’s for
Pod The smallest unit: one or more containers sharing network and volumes
Deployment Stateless applications, with rollout and rollback
ReplicaSet Keeps N identical pods; usually managed by a Deployment
Service A stable IP and DNS name for a group of pods
Ingress / Gateway API External HTTP(S) routing; Gateway API is the more expressive evolution
ConfigMap Non-sensitive configuration
Secret Sensitive data (base64-encoded, not encrypted by default)
PersistentVolumeClaim A request for persistent storage
Namespace Logical separation of resources, quotas, and permissions
DaemonSet One pod per node (log, monitoring, and network agents)
StatefulSet Applications with stable identity and storage (databases, queues)
Job / CronJob Tasks that run to completion; CronJob schedules them

Networking and storage

Networking: every pod gets its own IP, and the Kubernetes model requires pods to communicate across nodes without NAT. A CNI plugin (Calico, Cilium, Flannel, and others) implements this. Because pods are ephemeral and change IPs, a Service provides a stable virtual IP, and CoreDNS resolves names like web.shop.svc.cluster.local.

Storage: the application requests space with a PersistentVolumeClaim. A StorageClass indicates which CSI (Container Storage Interface) driver will provision the volume; the driver creates the disk at the provider, and the kubelet mounts it into the pod.

Self-healing in practice

Delete the pods and watch:

kubectl delete pod -n shop -l app=web --wait=false
kubectl get pods -n shop -l app=web -w

The ReplicaSet controller notices there are fewer pods than desired and creates replacements within seconds. The same principle applies at other levels: if the liveness probe fails, the kubelet restarts the container; if a node stops responding, the node controller marks it NotReady and, after the toleration period, its pods are evicted and recreated on other nodes.

This reconciliation model is the foundation of the entire CNCF ecosystem: operators, GitOps, and autoscalers are controllers applying the same idea to new problems. To experiment safely, spin up lightweight Kubernetes on your machine.

Summary

  • Kubernetes is declarative: you record the desired state, and controllers reconcile it
  • The API server is the hub: every component talks to it, and only it accesses etcd
  • The scheduler picks the node; the kubelet and the runtime (via CRI) run the containers
  • Applying a Deployment produces a ReplicaSet, Pods, a binding, and only then containers
  • Services, EndpointSlices, kube-proxy, and CoreDNS give ephemeral pods a stable address
  • CNI handles pod networking; CSI handles persistent volumes
  • Self-healing is a consequence of reconciliation loops, not a separate feature

In Kubernetes, nobody runs the deploy: you describe what you want, and dozens of small loops work until reality agrees with you.

Get updates on new posts and stay in the loop!