Zero Labs
Industry News / AI

Kubernetes Architecture Explained: From kubectl apply to a Running Pod

Source · Towards AI By Ake

From the publisher’s feed, collected in the ZeroLabs newsroom.

How the control plane, worker nodes, controllers, networking, and container runtime work together.Part 2 of the Kubernetes for MLOps seriesTL;DRKubernetes separates decision-making from execution.The control plane stores the desired state, validates changes, schedules Pods, and continuously reconciles the cluster.The worker nodes run the actual application containers.When you execute kubectl apply, Kubernetes:validates and stores the requested state;creates the required Pods;selects suitable worker nodes;starts the containers;checks their health;and sends traffic only when they are ready.The most important components are:kube-apiserver: the entry point to the cluster;etcd: the source of truth;kube-scheduler: selects nodes for Pods;controllers: correct differences between desired and actual state;kubelet: manages Pods on each worker node;containerd: starts and manages containers;CNI: provides Pod networking;CoreDNS and Services: provide stable service discovery.The Kubernetes Mental ModelThink of a Kubernetes cluster as an airport.The control plane is the control tower. It tracks the global state, decides where workloads should run, and reacts when something changes.The worker nodes are the runways and gates. They are where applications actually execute.The control plane does not run your FastAPI process itself. It records what should exist and coordinates the components that make it happen.Worker nodes:run Pods;start containers;perform health checks;configure networking;and report their status.If the control plane becomes temporarily unavailable, existing containers may continue running.However, the cluster can no longer adapt:new Pods cannot be scheduled;deployments cannot be updated;controllers cannot create replacements;and configuration changes cannot be applied.The applications may still be alive, but Kubernetes is no longer actively managing them.Kubernetes Architecture at a GlanceA Kubernetes cluster contains two main layers.Control planeThe control plane manages cluster state and decisions.Its core components are:kube-apiserver: exposes the Kubernetes API;etcd: stores Kubernetes objects;kube-scheduler: selects nodes for new Pods;kube-controller-manager: runs reconciliation loops;cloud-controller-manager: optionally connects Kubernetes to cloud infrastructure.Worker nodesWorker nodes execute application workloads.Their main components are:kubelet: manages assigned Pods;container runtime: starts containers;CNI plugin: configures Pod networking;Service proxy: routes Service traffic;CSI plugin: integrates persistent storage.Kubernetes Is a Declarative SystemYou do not usually tell Kubernetes:Start this container on worker node 3.Instead, you describe the state you want:apiVersion: apps/v1kind: Deploymentmetadata: name: fraud-detector namespace: productionspec: replicas: 3 selector: matchLabels: app: fraud-detector template: metadata: labels: app: fraud-detector spec: containers: - name: api image: registry.example.com/fraud-detector:v1.4.0 ports: - containerPort: 8000This object says:Keep three fraud-detector Pods running with this container image.Kubernetes controllers compare the desired state with the observed state.If only two Pods exist, Kubernetes creates another.If you change the image version, Kubernetes creates new Pods and removes the old ones.If a node fails, Kubernetes can create replacement Pods on healthy nodes.This process is called reconciliation:Observe the current state ↓Compare it with the desired state ↓Correct the difference ↓RepeatKubernetes is therefore not one large orchestrator issuing direct commands. It is a collection of specialized control loops communicating through the API.Control Plane Componentskube-apiserver: The Cluster GatewayThe API server is the main entry point to Kubernetes.When you run:kubectl apply -f fraud-detector.yamlkubectl sends a request to the API server.Kubelets, schedulers, controllers, operators also communicate through the Kubernetes API.Before storing a resource, the API server processes the request through several stages:Request ↓Authentication ↓Authorization ↓Admission control ↓Validation ↓PersistenceAuthenticationAuthentication answers:Who is making the request?Kubernetes can authenticate clients through certificates, ServiceAccount tokens, OIDC, webhooks, or cloud identity integrations.AuthorizationAuthorization answers:Is this identity allowed to perform the operation?RBAC controls which users or workloads can perform actions on specific resources.For example, an engineer may be allowed to view Pods without being allowed to delete them.Admission controlAdmission control can accept, reject, or modify a request.ValidationThe API server verifies that the object follows the Kubernetes API schema.An invalid field or negative replica count is rejected before persistence.WatchesKubernetes components react to changes through long-lived watch connections.The scheduler watches for unscheduled Pods.The kubelet watches for Pods assigned to its node.Controllers watch the objects they manage.This event-driven model allows the cluster to react without continuously polling every resource.etcd: The Source of Truthetcd stores Kubernetes API data.It contains objects such as:Pods;Deployments;Services;ConfigMaps;Secrets;Roles;and PersistentVolumeClaims.It stores Kubernetes state, not application data.kube-scheduler: Selecting a NodeA newly created Pod initially has no assigned node.The scheduler selects one through three main stages:Filter ↓Score ↓BindFilteringThe scheduler removes nodes that cannot run the Pod.A node may be rejected because:it lacks CPU or memory;it has no required GPU;its labels do not match;it has an unsupported taint;affinity rules reject it;or the required storage is unavailable in its zone.If no suitable node exists, the Pod remains Pending.kubectl describe pod fraud-detector-gpu -n productionThe Events section may show:FailedScheduling0/12 nodes are available:12 Insufficient nvidia.com/gpuScoringThe scheduler scores the remaining nodes based on factors such as:available resources;topology;affinity preferences;workload distribution;and storage constraints.BindingThe scheduler records the selected node through the API server.It does not start the container.The kubelet on the selected node performs the actual execution.kube-controller-manager: ReconciliationThe controller manager runs many control loops.Deployment controllerThe Deployment controller manages rollouts.When you change:image: registry.example.com/fraud-detector:v1.4.0it creates a new ReplicaSet and gradually replaces the previous version.ReplicaSet controllerThe ReplicaSet controller maintains the requested number of Pods.If three replicas are required but only two exist, it creates another.The distinction is important:the kubelet restarts failed containers inside an existing Pod;the ReplicaSet controller creates replacement Pods.Node controllerThe node controller monitors node heartbeats.When a node remains unavailable, its Pods can eventually be replaced on healthy nodes.The exact timing depends on the cluster configuration and Pod tolerations.EndpointSlice controllerWhen a Service selects Pods, the control plane creates EndpointSlices containing their network endpoints.Pod readiness determines whether an endpoint should receive normal traffic.cloud-controller-managerThe cloud-controller-manager connects Kubernetes to cloud infrastructure.Depending on the platform, it may help manage:cloud node information;routes;addresses;and external load balancers.For example, a LoadBalancer Service may cause the cloud integration to provision a supported external load balancer.Advanced HTTP routing is normally handled through a Gateway or Ingress controller.Worker Node Componentskubelet: The Node AgentThe kubelet runs on every worker node.It:registers the node;watches for assigned Pods;prepares volumes;coordinates networking;asks the runtime to start containers;executes probes;and reports status.Probes for ML servicesML inference services often require time to download and load model artifacts.Kubernetes provides three probe types.A practical configuration:startupProbe: httpGet: path: /startup port: 8000 periodSeconds: 5 failureThreshold: 60readinessProbe: httpGet: path: /ready port: 8000 periodSeconds: 10 failureThreshold: 3livenessProbe: httpGet: path: /live port: 8000 periodSeconds: 30 failureThreshold: 3The startup probe prevents Kubernetes from restarting the container while the model is still loading.Readiness controls traffic.Liveness controls restarts.Container RuntimeKubernetes does not directly create Linux containers.The kubelet communicates with the runtime through the Container Runtime Interface:kubelet ↓ CRIcontainerd ↓runc ↓Linux kernel ↓Application processcontainerd manages image pulls, container creation and container lifecycle.runc configures Linux namespaces, cgroups, filesystems, and process isolation.CNI: Pod NetworkingThe CNI implementation configures Pod networking.Services and CoreDNSPod IP addresses are temporary.A Service gives clients a stable IP address and DNS name.apiVersion: v1kind: Servicemetadata: name: fraud-detector namespace: productionspec: selector: app: fraud-detector ports: - port: 80 targetPort: 8000The Service selector identifies the Pods.EndpointSlices represent their addresses and readiness state.A Service proxy implementation then routes traffic to ready endpoints.CoreDNS provides names such as:fraud-detector.production.svc.cluster.localApplications therefore do not need to track individual Pod IPs.From kubectl apply to a Ready PodSuppose you run:kubectl apply -f fraud-detector-deployment.yamlHere is the complete flow.1. kubectl submits the resourcekubectl reads the YAML and sends it to the API server.2. The API server validates itThe request passes through:authentication;authorization;admission control;and schema validation.3. The desired state is storedThe API server persists the Deployment in etcd.The application is not running yet. Kubernetes has only recorded what should exist.4. Controllers create PodsThe Deployment controller creates a ReplicaSet.The ReplicaSet controller creates the required Pod objects.5. The scheduler selects nodesThe scheduler filters and scores nodes, then binds each Pod to a selected node.6. The kubelet prepares the PodThe kubelet:prepares networking;mounts volumes and configuration;pulls the image;and creates the containers.7. The runtime starts the applicationcontainerd starts the process:uvicorn fraud_detector:appThe Pod may now be Running, but that does not mean it is ready for traffic.8. Readiness succeedsThe startup probe allows model initialization to finish.The readiness probe confirms that the instance can safely handle requests.The EndpointSlice is updated, and the Service can begin routing traffic to the Pod.Kubernetes processes a deployment through validation, persistence, reconciliation, scheduling, node preparation, container execution, and readiness checks.References and Further ReadingKubernetes Components https://kubernetes.io/docs/concepts/overview/components/Kubernetes API Concepts https://kubernetes.io/docs/reference/using-api/api-concepts/Kubernetes Scheduler https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/Operating etcd Clusters for Kubernetes https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/EndpointSlices https://kubernetes.io/docs/concepts/services-networking/endpoint-slices/Authentication, Authorization, and Admission Control — official documentation for the request-processing pipeline used by the API server.Controllers — explains reconciliation loops, desired state, observed state, and how Kubernetes controllers communicate through the API server.Previous: Part 1- https://medium.com/towards-artificial-intelligence/why-kubernetes-exists-from-a-python-script-to-production-orchestration-5d825035f34b Next: Part 3 — Running ML Workloads: Deployments, Services, and Configuration (coming soon)Kubernetes Architecture Explained: From kubectl apply to a Running Pod was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.