Zero Labs
Industry News / Technology

The Kubernetes Handbook

Source · Towards AI By TechwidSush

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

Kubernetes: Designing for ScaleUnderstanding Kubernetes the way Architects DoDocker vs Kubernetes: Why Containers Alone Are Not EnoughBefore understanding Kubernetes, it is important to first understand Docker and the limitations it introduces when systems grow beyond a single machine.Understanding DockerDocker is a containerization platform. It allows you to package an application along with its dependencies, libraries, and runtime into a container. Consider packaging all the household stuff into one single bag which becomes easy to shift your home. This ensures the application runs consistently across environments — development, testing, and production.Containers are:LightweightFast to startShort-lived by designA container can stop, crash, or be recreated at any time. This behavior is acceptable for modern cloud-native systems, but it also introduces challenges when running applications at scale.Limitations of Docker in Real-World SystemsWhile Docker is excellent for packaging applications, it is not sufficient on its own for production-grade systems.1. Single Host LimitationDocker primarily operates on a single machine. If that host goes down, all containers running on it go down as well.In real production environments, applications must survive :- server failures, network issues, hardware crashes.Docker alone does not provide native clustering or cross-node failover.2. No Auto-HealingIf a container crashes, Docker does not automatically restart it unless explicitly configured.This means applications can become unavailable, manual intervention is often required. In enterprise systems, applications must heal themselves automatically.3. No Native Auto-ScalingWhen traffic increases, Docker does not automatically scale containers based on load.Scaling containers manually is error-prone, does not react in real time also is not feasible at scale.4. Missing Enterprise FeaturesDocker does not natively provideload balancingservice discoveryAPI gatewaysfirewall rulestraffic routinghealth-based restartsThese are mandatory requirements for enterprise-grade platforms.Why Kubernetes Is NeededKubernetes is a container orchestration platform designed to solve all the above problems.If Docker answers “How do I package my application?”,Kubernetes answers “How do I run, scale, heal, and manage applications in production?”What Kubernetes ProvidesKubernetes treats infrastructure as a cluster, not a single machine.It provides:Auto-healing — restarts failed containers automaticallyAuto-scaling — scales applications based on CPU/memory/loadHigh availability — applications survive node failuresBuilt-in load balancingService discoveryRolling deployments and rollbacksEnterprise-grade networking and securityContainers vs PodsDocker runs containers whereas Kubernetes runs pods. A pod is the smallest deployable unit in Kubernetes and can contain:one container (most common case)multiple tightly-coupled containers (sidecars)Kubernetes manages pods, not individual containers.Auto-Scaling and Auto-Healing with KubernetesKubernetes continuously monitors application health.If a container crashes → Kubernetes restarts it (auto-healing)If traffic increases → Kubernetes adds more pods (Horizontal Pod Autoscaler — HPA)If traffic decreases → Kubernetes removes extra podsThis makes applications resilient, cost-efficient, highly available.Docker Swarm vs KubernetesDocker Swarm is Docker’s native orchestration solution. It allows you to run containers across multiple machines.However:limited ecosystemweaker scaling capabilitiesless community adoptionfewer enterprise featuresAs systems grew in complexity, Kubernetes became the industry standard.Docker ShimEarlier, Kubernetes relied on Docker Shim, a compatibility layer that allowed Kubernetes to talk to Docker.Over time, Kubernetes moved away from Docker dependency and now supports multiple container runtimes, such as:containerdCRI-OThese runtimes implement the Container Runtime Interface (CRI) defined by Kubernetes. Docker solves containerization however Kubernetes solves orchestration.Kubernetes Architecture: Core Components ExplainedKubernetes is a cluster-based container orchestration platform designed to manage containerized applications at scale. At a high level, a Kubernetes cluster is divided into two major parts:Control Plane (Master Node) — manages the clusterWorker Nodes — run application workloadsTogether, these components enable auto-scaling, self-healing, service discovery, and enterprise-grade orchestration.1. Control Plane (Master Node)The Control Plane is the brain of the Kubernetes cluster. It does not run application workloads; instead, it makes global decisions and maintains the desired state of the cluster.Key Components of the Control Plane🔹 API ServerActs as the entry point to the Kubernetes clusterExposes Kubernetes APIs to users, CI/CD pipelines, and tools like kubectl.All cluster interactions go through the API serverExample: kubectl get pods → API Server → cluster state returned.🔹 SchedulerDecides which worker node should run a podEvaluates available CPU, memory, affinity rules, and constraints ensuring optimal resource utilization.🔹 etcdA distributed key-value store storing the entire cluster state (nodes, pods, secrets, configs)Kubernetes cannot function without etcdIf etcd is lost, the cluster loses its memory.🔹 Controller ManagerEnsures the desired state equals the actual stateManages controllers such as: ReplicaSet Controller, Node Controller, Deployment ControllerEnables auto-healing and auto-scalingExample: If a pod crashes, the controller recreates it automatically.🔹 Cloud Controller ManagerIntegrates Kubernetes with cloud providersHandles cloud-specific logic such as: Load balancers, Node lifecycle, Storage provisioningThis abstraction allows Kubernetes to run consistently across AWS, Azure, GCP, or on-prem.2. Worker NodeWorker nodes are where your application actually runs. Each worker node hosts pods and provides the runtime environment.PodThe smallest deployable unit in Kubernetes. A wrapper around one or more containers.Containers in a pod:Share the same network (IP)Share storage volumesA Pod is Kubernetes’ abstraction over containers, simplifying deployment and management via YAML instead of CLI commands.Key Components of a Worker Node🔹 KubeletNode-level agent that communicates with the control planeEnsures pods are running as expectedReports node and pod health back to the API ServerIf a container crashes, kubelet helps restart it.🔹 Container RuntimeResponsible for running containersDocker is not mandatoryCommon runtimes: containerd, CRI-OKubernetes interacts with runtimes via the Container Runtime Interface (CRI).🔹 kube-proxy (Networking)Manages pod networking and service communicationAssigns IP addresses to podsEnables internal load balancing and service discoverykubectl — The Kubernetes CLIkubectl is the command-line interface used to interact with the cluster.Examples: kubectl get nodes, kubectl apply -f pod.yamlkubectl get nodeskubectl apply -f pod.yamlkubectl describe podIt communicates directly with the API Server.Kops (Kubernetes Operations)Kops is a cluster lifecycle management tool used to:Create Kubernetes clustersUpgrade clustersModify configurationsDelete clustersPrimarily used for production-grade Kubernetes on cloud platforms.Replicas and Pod Sizing in KubernetesIn Kubernetes, the number of pod replicas is not chosen randomly. It is driven by two key factors:User traffic — how many concurrent users are accessing the applicationPod capacity — how many requests or connections a single pod can reliably handleAn ideal pod size is determined through performance testing and real usage patterns. Once this baseline is known, Kubernetes can scale the number of replicas up or down to maintain application performance and availability.For example, if one pod can safely handle 1,000 concurrent requests and the system expects 10,000 users, Kubernetes will run at least 10 replicas (with additional buffer for failures).Kubernetes Service (SVC): Why It Is NeededPods in Kubernetes are ephemeral — they can be created, destroyed, or replaced at any time. Every time a pod restarts, it receives a new IP address. This creates a problem: How do users or other services reliably connect to the application if pod IPs keep changing?This problem is solved by Kubernetes Services (SVC). A Service acts as a stable access layer in front of a dynamic set of pods.Key Features of Kubernetes Services1. Load BalancingA Kubernetes Service automatically distributes traffic across all healthy pod replicas.When a pod crashes and a new pod is created, traffic is seamlessly routed to the new podClients never need to know individual pod IPsInternally, this is handled by kube-proxy, which manages routing rules at the node levelThis ensures high availability and prevents traffic from being sent to failed pods.2. Service DiscoveryServices provide built-in service discovery using labels and selectors.Pods are tagged with labels (e.g., app=payments)The Service selects pods based on these labelsWhen pods go down or new replicas come up, the Service automatically updates the routing.Because all pods are created from the same YAML definition via a ReplicaSet, new pods always match the same labels — making discovery automatic and reliable.This eliminates the need to track individual IP addresses manually.3. Exposing Applications to the External WorldKubernetes Services also enable applications to be accessed outside the cluster.Depending on the use case, a Service can be exposed as:ClusterIP — internal access only (default)NodePort — access via node IP and portLoadBalancer — integrates with cloud load balancers (AWS ALB/ELB, Azure LB, etc.)This allows Kubernetes to cleanly separate internal networking from external access, while keeping the application architecture simple.🔐 Kubernetes Security — Understanding RBAC (Role-Based Access Control)Security in Kubernetes is not optional — it is foundational. In real-world production clusters, controlling who can do what is critical because a single wrong action (like deleting a namespace or secret) can cause system-wide outages.Kubernetes security is largely enforced through RBAC (Role-Based Access Control), which defines permissions based on roles instead of individuals.At a high level, RBAC answers three questions:Who is making the request?What are they trying to access?Are they allowed to perform that action?🧩 Two Dimensions of Kubernetes RBACKubernetes RBAC applies to two types of identities:1️⃣ Users (Human Access)2️⃣ Service Accounts (Application / Pod Access)Both are controlled using the same RBAC model.👤 User Management in KubernetesIn local environments like Minikube or Kind, users often get admin-level access by default. This is acceptable for learning, but dangerous in enterprise environments.In real organizations:Kubernetes does NOT manage users directlyUser authentication is offloaded to external identity providersCommon Identity Providers:AWS IAM (EKS)Azure AD (AKS)GCP IAM (GKE)OAuth / OIDC providers (Keycloak, Okta)Example (EKS):Users authenticate using IAMIAM users or groups are mapped to Kubernetes RBAC rolesAccess is granted based on role, not individual permissionsThis ensures least privilege access, clear audit trails and Easier onboarding/offboarding.🤖 Service Accounts — Securing Pod AccessService Accounts define what permissions a pod has inside the cluster.By default:Every pod gets a default service accountThis may unintentionally grant more access than requiredWhy Service Accounts Matter:A pod might try to:Read Kubernetes SecretsAccess ConfigMapsDelete resourcesCommunicate with the API ServerWithout RBAC:Any compromised pod can become a security riskWith RBAC:Pods get only the permissions they needAccess to sensitive resources is tightly controlledService Accounts are created using YAML and attached to pods or deployments.🧱 Core RBAC Building Blocks in KubernetesKubernetes RBAC is built using three main components:1️⃣ Subjects (Users & Service Accounts)These are who the permissions apply to:Human users (via identity providers)Service accounts (for pods and workloads)2️⃣ Roles & ClusterRoles (What Can Be Done)Roles define allowed actions.🔹 RoleNamespace-scopedControls access within a single namespaceExample: Allow read-only access to pods in dev namespace🔹 ClusterRoleCluster-wideControls access across all namespacesExample: Allow viewing nodes, namespaces, or cluster-wide resourcesRoles specify:Resources (pods, secrets, configmaps)Verbs (get, list, create, delete, update)3️⃣ RoleBinding & ClusterRoleBinding (Who Gets the Role)Bindings connect roles to users or service accounts.🔹 RoleBindingGrants a Role within a namespace🔹 ClusterRoleBindingGrants a ClusterRole across the entire clusterThis separation ensures:Fine-grained access controlClear permission boundariesSafer multi-team clusters🛡️ Why RBAC Is Critical in ProductionRBAC protects Kubernetes clusters from:Accidental deletionsUnauthorized accessLateral movement after pod compromiseExcessive permissionsFor large organizations:Multiple teamsShared clustersCompliance requirementsRBAC becomes non-negotiable. Now that we understand the core concepts, the real learning begins with implementation.🧭 Core kubectl Commands – Responsibilities & When to Use📦 Common Resource-Specific Examples🔑 When to Use apply vs createkubectl create helps to creating resources once (imperative)kubectl apply helps managing resources over time (declarative – best practice)In the next lbog, we’ll apply this in a cloud environment and explore real-world production challenges.Photo by Reuben Juarez on UnsplashAs systems grew in complexity, Kubernetes became the industry standard.The Kubernetes Handbook was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.