Volume 5 · Chapter 3 — Advanced .NET Cloud Native Architecture

Kubernetes Fundamentals

Goutham Mayaluri 7 min read .NETC#KubernetesCloud Native

3.1 Introduction

Kubernetes is a container orchestration platform that automates deployment, scaling, networking, and lifecycle management of containerized applications. For enterprise .NET systems it provides a consistent platform for running microservices across environments, with self-healing and declarative desired-state management. The core idea to grasp is that you declare the desired state and Kubernetes continuously reconciles the actual state to match it.

3.2 Architecture: Control Plane and Nodes

A cluster has a control plane (the API server, scheduler, controller manager, and etcd - which store and manage cluster state and desired configuration) and worker nodes (running the kubelet, container runtime, and kube-proxy) that run your application pods. The control plane decides what should run where; the nodes run it.

flowchart TB
  subgraph CP["Control Plane"]
      API["API Server"]
      Sched["Scheduler"]
      CM["Controller Manager"]
      Etcd["etcd (state)"]
  end
  CP --> N1["Worker Node 1"]
  CP --> N2["Worker Node 2"]
  N1 --> P1["Pods (containers)"]
  N2 --> P2["Pods (containers)"]

3.3 Core Objects

APodis the smallest deployable unit (one or more containers sharing network/storage). ADeploymentmanages a set of pod replicas and provides rolling updates and rollback. AServicegives a stable virtual IP and DNS name to a set of pods.ConfigMapsandSecretsexternalize configuration and sensitive values.


// Deployment manifest (YAML): replicas, resources, and health probes.
//   apiVersion: apps/v1
//   kind: Deployment
//   spec:
//     replicas: 3
//     template:
//       spec:
//         containers:
//         - name: payments-api
//           image: acr.azurecr.io/payments-api:1.4.2
//           resources:
//             requests: { cpu: "250m", memory: "256Mi" }   # scheduling basis + HPA
//             limits:   { cpu: "500m", memory: "512Mi" }   # hard cap
//           livenessProbe:  { httpGet: { path: /health/live,  port: 8080 } }
//           readinessProbe: { httpGet: { path: /health/ready, port: 8080 } }

3.4 Self-Healing, Scaling, and Rolling Updates

Kubernetes continuously reconciles desired vs actual state: it restarts failed containers, replaces unhealthy pods, and reschedules workloads off failed nodes. It scales via ReplicaSets (Deployments maintain the desired replica count) and the Horizontal Pod Autoscaler, and it performs zero-downtime rolling deployments by gradually replacing old pods with new ones, gated by readiness probes.

3.5 Networking, ConfigMaps, and Secrets

Kubernetes provides pod networking, service discovery (Services), external routing (Ingress), and network policies for segmentation. ConfigMaps hold non-sensitive configuration; Secrets hold sensitive values (though for real secrets, integrate a vault via the CSI driver). This externalization is what makes containers portable across environments.

Senior Interview Question

Why is Kubernetes needed if Docker already runs containers?

Docker runs individual containers on a single host, but running containersat scale, in production, across many hostsrequires orchestration - which is what Kubernetes provides. Docker gives you the container (build, run, one host); Kubernetes manages fleets of containers across a cluster of machines and handles all the operational concerns that Docker alone doesn’t. Specifically: scheduling - deciding which node each container runs on based on resources and constraints; scaling - running many replicas and adjusting their number automatically (Horizontal Pod Autoscaler) to meet load, plus scaling the cluster’s nodes; self-healing - continuously reconciling desired versus actual state so failed containers are restarted, unhealthy pods replaced, and workloads rescheduled off failed nodes, all automatically; service discovery and load balancing - stable network identities (Services) and routing so containers can find and reach each other and external traffic reaches them even as pods come and go; rolling updates and rollbacks - deploying new versions with zero downtime by gradually replacing pods gated by health checks, and reverting on failure; configuration and secret management - externalizing config so the same image runs everywhere; and declarative management - you declare the desired state and Kubernetes makes it so and keeps it that way. Doing all of this by hand with Docker across many hosts - deciding placement, restarting crashed containers, load-balancing, rolling out updates safely, scaling - would be enormous, error-prone manual work. So the relationship is that Docker (or any container runtime) runs the containers, and Kubernetes orchestrates them: it’s the layer that automates deployment, scaling, networking, healing, and lifecycle management of containerized workloads across a cluster, providing the reliability and automation that production microservices need. That’s why a production cloud-native system uses both - containers as the packaging/runtime unit, and Kubernetes (or a managed equivalent) as the orchestrator - and why “Docker already runs containers” doesn’t remove the need for orchestration; it’s precisely the many-containers-across-many-hosts, always-on, self-healing, scalable operation that Kubernetes exists to handle.

Principal Engineer Question

Explain how Kubernetes' declarative, desired-state model works and why it matters.

Kubernetes is built on a declarative, desired-state reconciliation model, which is central to how it provides reliability and automation. Instead of issuing imperative commands (“start this container on that node,” “restart it if it dies”), you declare the desired state of the system in manifests - “I want 3 replicas of this deployment, using this image, with these resources and health probes, exposed by this service” - and submit that to the API server, which stores it (in etcd) as the intended state. Kubernetes then runs controllers that continuously observe the actual state of the cluster and work to reconcile it toward the declared desired state: a control loop compares desired versus actual and takes corrective action whenever they diverge. If a pod crashes or a node fails, actual state no longer matches desired (fewer than 3 healthy replicas), so the controller creates replacement pods and the scheduler places them - self-healing happens automatically without human intervention. If you update the desired image, the deployment controller performs a rolling update to converge to the new state, gated by readiness so it’s zero-downtime. This matters for several reasons. Reliability and self-healing: the system constantly drives itself back to the desired state, so transient failures (crashed containers, lost nodes) are corrected automatically, which is exactly the resilience cloud-native systems need. Predictability and idempotency: applying the same manifest repeatedly converges to the same state, so deployments are repeatable and drift is corrected, rather than depending on a sequence of imperative steps that assume a starting state. Infrastructure/config as code: because the desired state is declarative data (YAML), it’s version-controlled, reviewable, and reproducible - you can recreate the whole system from the manifests. Automation at scale: operators declare intent and Kubernetes handles the how - placement, scaling, healing, updates - across many nodes, which is what makes running large fleets feasible. And it enables patterns like GitOps, where the desired state lives in Git and a controller continuously reconciles the cluster to match. Contrast this with an imperative approach where you’d have to script every action and handle every failure case yourself, with no guarantee the system stays in the intended state. So the declarative desired-state model - declare intent, let controllers continuously reconcile actual toward desired - is what gives Kubernetes its self-healing, its idempotent repeatable deployments, its infrastructure-as-code nature, and its ability to automate operations at scale, and it’s the conceptual key to understanding why Kubernetes behaves the way it does and why it’s so powerful for cloud-native operations.

3.6 Enterprise Scenario

A bank runs hundreds of .NET microservice instances on Kubernetes. It declares each service’s desired state - replica count, image, resource requests/limits, and liveness/readiness probes - and Kubernetes continuously reconciles: restarting failed containers, replacing unhealthy pods, rescheduling off failed nodes, autoscaling replicas under load, and performing zero-downtime rolling updates gated by readiness. Configuration is externalized via ConfigMaps and secrets via a vault, so the same images run across environments.

Chapter Revision Notes

  • Kubernetes orchestrates containers: scheduling, scaling, networking, healing, and lifecycle.
  • Control plane (API server, scheduler, etcd) manages state; worker nodes run pods.
  • Pods (smallest unit), Deployments (replicas + rolling updates), Services (stable networking).
  • The declarative desired-state model continuously reconciles actual to desired - enabling self-healing.
  • Externalize config (ConfigMaps) and secrets (vault via CSI) for portability.