Kubernetes Introduction

Kubernetes is an open-source container orchestration platform that automates deployment, scaling, and management of containerized applications.

Kubernetes (often abbreviated as K8s) is an open-source platform originally developed by Google and donated to the Cloud Native Computing Foundation (CNCF). It solves the core operational problem of running containers reliably at scale: automatically scheduling workloads across a cluster of machines, healing failures, rolling out updates without downtime, and scaling replicas up or down in response to load. Understanding Kubernetes is essential for any engineer working in modern cloud-native or DevOps environments.

Why Kubernetes Exists

Before container orchestration, teams ran containers directly on VMs using tools like Docker Compose. This worked for single-machine setups but fell apart at scale: there was no automatic recovery when a host went down, no built-in load balancing across hosts, and no standard way to roll out a new image version safely. Kubernetes addresses all of these by treating the entire fleet of machines as one logical compute pool.

Core Building Blocks

Resource Role
Pod The smallest deployable unit; wraps one or more containers that share a network and storage
ReplicaSet Ensures a specified number of Pod replicas are always running
Deployment Manages ReplicaSets, enabling rolling updates and rollbacks
Service Provides a stable DNS name and IP address in front of a dynamic set of Pods
ConfigMap Stores non-sensitive configuration data as key-value pairs
Secret Stores sensitive data (passwords, tokens) in base64-encoded form
Ingress Routes external HTTP/HTTPS traffic to Services based on host and path rules
Namespace Virtual cluster that isolates resources within a physical cluster
PersistentVolumeClaim Requests durable storage for stateful workloads
StatefulSet Manages stateful applications with stable identities and persistent storage

How Kubernetes Works

A Kubernetes cluster has two types of machines: control plane nodes that make decisions (scheduling, state reconciliation, API serving) and worker nodes that run application workloads. Users interact with the cluster exclusively through the kube-apiserver using kubectl or other API clients. The desired state of every resource is stored in etcd. Controllers continuously reconcile actual state with desired state — if a Pod crashes, the controller creates a replacement.

A First Manifest

Every Kubernetes resource is described as a YAML manifest. Here is the simplest possible workload — a single nginx Pod:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-demo
  labels:
    app: nginx
spec:
  containers:
    - name: nginx
      image: nginx:1.27
      ports:
        - containerPort: 80
      resources:
        requests:
          cpu: "100m"
          memory: "64Mi"
        limits:
          cpu: "200m"
          memory: "128Mi"

Apply it and inspect the result:

kubectl apply -f nginx-demo.yaml
# pod/nginx-demo created

kubectl get pods
# NAME         READY   STATUS    RESTARTS   AGE
# nginx-demo   1/1     Running   0          12s

kubectl describe pod nginx-demo
# ... events, IP, node assignment, container state

kubectl delete pod nginx-demo
# pod "nginx-demo" deleted

In real workloads you would use a Deployment instead of a bare Pod, so Kubernetes can reschedule it if it fails.

The Reconciliation Loop

The key mental model in Kubernetes is desired state vs. actual state. You declare what you want (three replicas of my app), and controllers make it happen and keep it that way. You never imperatively instruct the cluster to "start a container on node-3"; you tell the cluster the desired outcome and let the scheduler decide where to place it.

Common Mistakes

  • Running bare Pods in production. A bare Pod is not rescheduled if it fails or its node disappears. Always use a Deployment or StatefulSet.
  • Using the latest tag. latest is mutable; two deployments of the same manifest may pull different images. Pin to a specific digest or version tag.
  • Skipping resource requests and limits. Without them, a noisy-neighbour Pod can exhaust a node's CPU or memory, evicting other Pods.
  • Ignoring liveness and readiness probes. Without probes, Kubernetes sends traffic to Pods that are not yet ready and does not restart Pods that are deadlocked.
  • Treating Kubernetes as a VM manager. Kubernetes is a declarative system; attempting to manage it imperatively (manually patching live objects, avoiding YAML) creates configuration drift.

Best Practices

  • Store all manifests in Git and apply them through a CI/CD pipeline (GitOps).
  • Define resources.requests and resources.limits on every container.
  • Use namespaces to separate environments or teams within one cluster.
  • Always define livenessProbe and readinessProbe on long-running containers.
  • Use specific image tags or digest pinning rather than latest.

Interview Questions

1. What is Kubernetes and what problem does it solve?

Kubernetes is an open-source container orchestration platform. It solves the problem of running containerized workloads reliably at scale by automating scheduling, self-healing, rolling updates, service discovery, and horizontal scaling across a cluster of machines.

2. What is the difference between a Pod and a container?

A container is a process running inside an isolated filesystem. A Pod is the Kubernetes abstraction that wraps one or more containers that share the same network namespace (same IP and port space) and can share storage volumes. Kubernetes schedules Pods, not individual containers.

3. What does "desired state" mean in Kubernetes?

You declare what you want (e.g., three replicas of an app using a specific image), and Kubernetes continuously reconciles the actual state of the cluster to match it. If a Pod dies, a controller detects the drift and creates a new one — without human intervention.

4. What happens when you run kubectl apply -f manifest.yaml?

kubectl serializes the manifest and sends an HTTP request to the kube-apiserver. The API server validates the object, stores it in etcd, and notifies the relevant controller. The controller acts on the new desired state — for example, the Deployment controller creates ReplicaSets and Pods. The scheduler assigns Pods to nodes, and the kubelet on each node pulls the image and starts the container.

5. Why should you not use bare Pods in production?

A bare Pod is not managed by any controller. If the Pod fails or the node it runs on goes down, no controller will reschedule it. A Deployment wraps Pods in a ReplicaSet, which ensures the desired number of replicas are always running and reschedules failed Pods automatically.

6. What is the role of etcd in Kubernetes?

etcd is the distributed key-value store that holds the entire desired state of the cluster — all resource definitions, configurations, and secrets. The kube-apiserver is the only component that reads from and writes to etcd directly. If etcd is lost without a backup, cluster state cannot be recovered.

7. How does Kubernetes achieve high availability for applications?

By running multiple replicas of a Pod (via Deployment or ReplicaSet), spreading them across nodes using topology constraints, using readinessProbe to remove unhealthy Pods from Service endpoints, and performing rolling updates that keep old Pods running until new ones pass their readiness check.

Summary

  • Kubernetes automates container scheduling, self-healing, scaling, and rolling updates across a cluster.
  • Every resource is described as a YAML manifest expressing desired state; controllers reconcile actual state to match it.
  • The core primitives are Pod, Deployment, Service, ConfigMap, Secret, Ingress, and Namespace.
  • Always use a controller (Deployment, StatefulSet) rather than bare Pods in production.
  • Resource requests/limits and health probes are non-negotiable for production workloads.

Continue Learning

Next: Kubernetes Architecture

Was this guide helpful?

CodeWithVenu is free to read, with no paywall. If this guide saved you time or helped you prepare, a small voluntary contribution helps me write more practical tutorials, architecture guides, and interview-prep content.