Maintenance

Site is under maintenance — quizzes are still available.

Go to quizzes

What Is Kubernetes

Learn what Kubernetes is and why it's essential for container orchestration in this hands-on tutorial.

Focus: what is kubernetes and why use it

Sponsored

Ever tried to manually restart a container that crashed at 3 AM, only to find three more containers have failed by the time you finished? That's the pain Kubernetes was built to eliminate. In this lesson, you'll learn what Kubernetes is and, more importantly, why you should use it — not as a buzzword, but as a practical tool that saves your weekends and keeps your applications running.

The Problem This Lesson Solves

Running containers in production is hard. A single Docker container starts fast and behaves well on your laptop, but the moment you need to run 10, 100, or 1,000 of them across multiple servers, everything breaks:

  • Crash loops: A container dies. Nobody is watching. Your app goes down.
  • Scaling chaos: Traffic spikes at 2 PM. You SSH into a server and manually start 5 more containers, then forget to stop them at night.
  • Network spaghetti: Container A needs to talk to Container B. But their IPs change every time they restart. You cobble together scripts to update /etc/hosts — and they fail silently.
  • Deployment downtime: You push a new version. You stop the old container. You start the new one. In that 5-second gap, customers see an error page.

Before Kubernetes, teams built their own fragile toolchains: scripts, cron jobs, custom health checks, load balancer configs. The result? High cognitive load, brittle systems, and “works on my machine” syndrome.

This lesson teaches you what Kubernetes is — a platform that solves these exact problems — and why it has become the standard for container orchestration.

Core Concept / Mental Model

Think of Kubernetes as the operating system for your data center. Just as an OS manages processes, memory, and disk on a single machine, Kubernetes manages containers, networking, and storage across a cluster of machines.

The Key Idea: Declarative Desired State

You tell Kubernetes what you want (e.g., “run 3 copies of my web app, each available on port 80”), and Kubernetes constantly works to make reality match that description. If a container crashes, Kubernetes starts a new one. If a server goes down, Kubernetes reschedules its containers onto healthy servers.

This is a declarative model: you describe the goal, not the step-by-step instructions.

Pro tip: Contrast this with the imperative approach of a deployment script where you say “start container A, then wait 5 seconds, then start container B…” — fragile and error-prone.

Core Building Blocks (in 30 seconds)

  • Pod: The smallest deployable unit — one or more containers that share networking and storage.
  • Node: A worker machine (physical or virtual) in the cluster.
  • Cluster: The set of nodes managed by Kubernetes.
  • Control Plane: The brain of the cluster — it makes global decisions (scheduling, scaling, responding to failures).
  • Deployment: A controller that ensures the desired number of Pod replicas are running.
  • Service: A stable network endpoint for accessing a set of Pods, even as Pods come and go.

Analogy: Imagine a hotel (cluster). The control plane is the front desk. Each room is a node. The guests staying in a room are Pods. The Deployment is the housekeeping manager who ensures every booked room is occupied by the right number of guests. The Service is the hotel phone number — call that number and you reach any available room.

How It Works Step by Step

Here's the typical lifecycle of a request in a Kubernetes cluster:

  1. You submit a YAML file to the cluster via kubectl apply. The file declares: “Run 3 copies of my Docker image acme/web:v2, each exposing port 8080.”
  2. The API server validates your request and stores the desired state in etcd (the cluster's database).
  3. The scheduler watches for Pods that haven't been assigned to a Node yet. It picks a healthy Node and assigns the Pod.
  4. The kubelet on that Node receives the instruction, pulls your Docker image, and starts the container(s).
  5. The kube-proxy configures networking so that traffic to the Service IP gets forwarded to one of the running Pods.
  6. The controller manager continuously compares desired state vs. actual state. If one Pod crashes, it detects the mismatch and starts a replacement (back to step 3).

This cycle runs 24/7 without human intervention.

Example: Scaling

  • Your Deployment says replicas: 3. Current load: 100 requests/second.
  • Traffic spikes to 500 rps. Pods start to timeout.
  • You update the YAML: replicas: 6. Kubernetes automatically schedules 3 more Pods.
  • Traffic drops to 200 rps. You change back to replicas: 3. Kubernetes gracefully stops the extra Pods.

No SSH, no scripts, no manual port management.

Hands-on Walkthrough

Let's run a real Kubernetes cluster on your machine using minikube. It creates a single-node cluster for local development.

Prerequisites

  • Docker installed (docker --version)
  • 2 GB free RAM
  • kubectl installed (kubectl version --client)

Step 1: Start Minikube

minikube start --driver=docker

Expected output:

😄  minikube v1.31.2 on Darwin 13.4
✨  Using the docker driver based on existing profile
👍  Starting control plane node minikube in cluster minikube
🏃  Updating the running docker "minikube" container ...
🐳  Preparing Kubernetes v1.27.3 on Docker 24.0.4 ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster

Step 2: Run Your First Deployment

Create a file named nginx-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.25
          ports:
            - containerPort: 80

Apply it:

kubectl apply -f nginx-deployment.yaml

Check the Pods:

kubectl get pods

Expected output (names will vary):

NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-7c79d56f49-6fk2k   1/1     Running   0          45s
nginx-deployment-7c79d56f49-8x7q7   1/1     Running   0          45s
nginx-deployment-7c79d56f49-9w3n9   1/1     Running   0          45s

Step 3: Expose the Deployment as a Service

kubectl expose deployment nginx-deployment --type=NodePort --port=80

See the Service:

kubectl get service

Step 4: Simulate a Crash

Let's delete one Pod and watch Kubernetes heal itself:

kubectl delete pod nginx-deployment-7c79d56f49-6fk2k
kubectl get pods -w   # watch the events

You'll see the deleted Pod disappear, and a new one automatically created within seconds:

nginx-deployment-7c79d56f49-6fk2k   Terminating
nginx-deployment-7c79d56f49-4hg7q   Pending
nginx-deployment-7c79d56f49-4hg7q   ContainerCreating
nginx-deployment-7c79d56f49-4hg7q   Running

This is the core promise of what Kubernetes is: self-healing at scale.

Compare Options / When to Choose What

Approach Pros Cons Best for
Docker Compose Simple, easy for dev, no cluster needed Single host, no auto-healing, no auto-scaling Local dev, single-machine testing
Docker Swarm Native Docker integration, simpler to set up than Kubernetes Smaller ecosystem, fewer features, less community support Teams already deep in Docker, small production loads
Kubernetes Portable (any cloud or on-prem), self-healing, auto-scaling, vast ecosystem Steeper learning curve, higher resource overhead Production workloads, multi-service apps, any scale above trivial
Managed Kubernetes (EKS, GKE, AKS) Hassle-free control plane, integrated with cloud services Vendor lock-in, higher cost Teams that want to focus on apps, not ops

When to use Kubernetes

  • Your app runs more than 3 containers.
  • You need automatic recovery from failures.
  • You want to scale up and down without human intervention.
  • You deploy multiple times per day and need zero-downtime.

When not to use Kubernetes

  • You're running a single container (just use Docker).
  • You're in early prototyping phase (Docker Compose is fine).
  • Your team has no one willing to learn the operational overhead.

Pro tip: Many teams adopt managed Kubernetes from day one to avoid control-plane toil. The learning curve is still there, but you don't have to become an etcd expert.

Troubleshooting & Edge Cases

Error: Pod stuck in Pending

kubectl describe pod <pod-name>

Look for events like 0/1 nodes are available: Insufficient cpu. This means your Minikube VM (or cluster) doesn't have enough CPU or memory.

Fix: minikube stop && minikube start --cpus=2 --memory=2048

Error: ImagePullBackOff

kubectl logs <pod-name>

Usually the image name is wrong or the image doesn't exist. Check your image: field.

Fix: Use a correct public image (e.g., nginx:1.25) or push your image to a registry first.

Common Mistake: Forgetting to delete Pods when scaling down

Actually, Kubernetes handles this automatically — a common misunderstanding is that you must manually delete Pods. You don't. Just change replicas in the YAML and re-apply.

Common Mistake: Typos in YAML

YAML is whitespace-sensitive. One wrong indent and kubectl apply will produce a confusing error. Use kubectl apply --dry-run=client to validate before applying.

Edge Case: Node goes down

If a worker Node fails, Kubernetes automatically reschedules all Pods from that Node to healthy nodes. It may take a few minutes (default pod-eviction-timeout is 5 minutes). You don't have to do anything, but you will see a burst of Pending Pods until they land elsewhere.

What You Learned & What's Next

You now have a clear answer to what is Kubernetes and why use it:

  • Kubernetes is a container orchestration platform that automates deployment, scaling, and management.
  • It uses a declarative model — you say what you want, not how.
  • Core concepts: Pods, Deployments, Services, Nodes, Control Plane.
  • You ran a real cluster with Minikube, deployed an Nginx app, saw self-healing in action.
  • You compared Kubernetes with alternatives and know when to adopt it.

What's next: The next lesson dives into Pods — the smallest compute unit in Kubernetes. You'll learn how to configure them, pass environment variables, mount volumes, and what health probes are.

Pro tip: Keep your Minikube cluster running. In the next lesson, you'll modify this same deployment to add health checks.

Practice recap

Practice: Keep your Minikube cluster running. Edit the nginx-deployment.yaml and change replicas from 3 to 5, then run kubectl apply -f nginx-deployment.yaml again. Run kubectl get pods to see two new Pods appear automatically. Next, delete the Pod file and re-apply to scale back down. This will train your muscle memory for declarative updates.

Common mistakes

  • Thinking Kubernetes is a container runtime: Kubernetes orchestrates containers, but it still relies on Docker or containerd to actually run them.
  • Writing YAML with incorrect indentation: Kubernetes YAML is strict. One extra space breaks the entire config.
  • Forgetting to expose a Service: A Deployment creates Pods, but without a Service, those Pods are not reachable from outside the cluster.

Variations

  1. Instead of Minikube, use kind (Kubernetes in Docker) for even lighter-weight local clusters.
  2. Instead of imperative kubectl expose, use declarative YAML for Services the same way you did for Deployments.
  3. Instead of rolling your load balancing, use managed Kubernetes (EKS, GKE, AKS) which provide integrated load balancers.

Real-world use cases

  • A fintech startup runs 50 microservices on a 3-node Kubernetes cluster, automatically healing from pod crashes without manual intervention.
  • An e-commerce platform uses Kubernetes Horizontal Pod Autoscaler to scale its checkout service from 5 to 50 pods during Black Friday traffic spikes.
  • A gaming company runs AI training jobs on Kubernetes, using its batch scheduling to efficiently pack GPU workloads across available nodes.

Key takeaways

  • Kubernetes is a portable, extensible platform for managing containerized workloads and services.
  • It uses a declarative model: you define the desired state, and Kubernetes makes it happen.
  • Core building blocks: Pods, Deployments, Services, Nodes, and the Control Plane.
  • Self-healing: if a container crashes, Kubernetes automatically restarts it without human involvement.
  • Managed Kubernetes (EKS, GKE, AKS) reduces operational overhead compared to self-managed clusters.
  • Start with Minikube or kind for local learning; move to managed services for production.

Sponsored

Sponsored

Discussion

Questions, corrections, and tips help everyone reading this page.

0 comments

Add a comment

Shown publicly with your comment.

Be constructive · max 4,000 characters

No comments yet — start the thread.

Related tutorials, quizzes, and articles for this topic.