Kubernetes for Beginners: The Visual Guide

Understand Pods, Nodes, and Clusters with visual diagrams and real-world analogies. The complete guide to container orchestration.

Kubernetes for Beginners: The Visual Guide
πŸ“§

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free

Managing one Docker container is easy. Managing hundreds across multiple servers? That’s a nightmare β€” unless you have an orchestra conductor.

This is where Kubernetes (K8s) comes in. It’s the operating system for the cloud.

Introduction

What You'll Learn
  • What Kubernetes actually solves (The β€œWhy”)
  • The full architecture: Control Plane vs. Worker Nodes
  • Key objects: Pods, Deployments, Services
  • How to write real YAML manifests
  • 10 essential kubectl commands
  • A hands-on project: Deploy your first app
Mental Model: The Orchestra Conductor

Imagine a massive orchestra with 100 musicians (Containers).

  • Docker is the individual musician. They know how to play their instrument.
  • Kubernetes is the Conductor.

The Conductor doesn’t play an instrument. Instead, they:

  • Tell musicians when to start/stop (Scheduling)
  • Replace a musician if they faint (Self-healing)
  • Ensure the volume is balanced (Scaling)

Without the Conductor, you just have noise. With Kubernetes, you have a symphony.


Kubernetes Architecture

A Kubernetes cluster is split into two parts: The Brain (Control Plane) and The Muscle (Worker Nodes).

Kubernetes Architecture: Control Plane and Nodes
Kubernetes Architecture: Control Plane + Worker Nodes

The Control Plane Components

ComponentNicknameWhat It Does
API ServerThe Front DeskEverything talks here. kubectl sends commands here.
SchedulerThe Placement AgencyDecides which node runs which Pod.
EtcdThe Distributed NotebookStores the entire cluster state (replicated, fault-tolerant).
Controller ManagerThe WatchdogContinuously checks: β€œIs the current state = desired state?”

The Worker Node Components

ComponentWhat It Does
KubeletThe site manager. Ensures containers are running as instructed.
Kube-proxyThe network traffic cop. Routes traffic to the right Pod.
Container RuntimeThe engine (e.g., containerd). Actually runs the containers.

Key Concepts: The β€œK8s Objects”

1. Pod β€” The Atom

The smallest deployable unit. Usually contains one container.

Pods are Ephemeral!

Pods die. They can be killed by the scheduler, OOMKilled, or evicted. Never rely on a single Pod staying alive. That’s what Deployments are for.

2. Deployment β€” The Blueprint

Defines how many copies (replicas) of a Pod you want. Deployments self-heal β€” if a Pod dies, the Deployment restarts it.

# my-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  replicas: 3          # Run 3 copies at all times
  selector:
    matchLabels:
      app: my-nginx
  template:
    metadata:
      labels:
        app: my-nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80

3. Service β€” The Stable Phone Number

Pods get new IP addresses every time they restart. A Service gives them a stable address.

Kubernetes Service Discovery Diagram
Service: The Stable Front Door to Pods
# my-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
spec:
  selector:
    app: my-nginx      # Routes to Pods with this label
  ports:
  - port: 80
    targetPort: 80
  type: LoadBalancer   # Exposes externally (or NodePort for local dev)
Service Types at a Glance
  • ClusterIP (default): Only accessible inside the cluster.
  • NodePort: Exposes on each node’s IP + a static port (30000–32767).
  • LoadBalancer: Provisions a cloud load balancer (AWS/GCP/Azure).

Setting Up: Minikube (Local Kubernetes)

Before running kubectl, you need a cluster. Minikube runs a single-node cluster on your laptop.

minikube start

Start a local Kubernetes cluster (downloads K8s and starts a VM/container)

beginner
minikube start --driver=docker
  • β€’--driver=docker uses Docker as the backend (no VM needed)
  • β€’First run takes 2-5 minutes to download
  • β€’minikube status to check if it's running
minikube status

Check that your local cluster is running

beginner
minikube\ntype: Control Plane\nhost: Running\nkubelet: Running\napiserver: Running\nkubeconfig: Configured

Hands-On: Essential kubectl Commands

kubectl is your command-line remote control for the entire cluster.

1. Get Nodes

kubectl get nodes

List all nodes in the cluster and their status

beginner
NAME STATUS ROLES AGE VERSION\nminikube Ready control-plane 5m v1.29

2. Apply a YAML Manifest

kubectl apply -f my-deployment.yaml

Create or update resources from a YAML file

beginner
deployment.apps/my-nginx created
  • β€’The primary way to deploy in Kubernetes
  • β€’-f can point to a file OR a directory
  • β€’Re-run to update β€” Kubernetes diffs the change

3. Get All Resources

kubectl get all

List all Pods, Services, Deployments, and ReplicaSets in the current namespace

beginner
  • β€’-n kube-system to see the system namespace
  • β€’--all-namespaces (-A) to see everything cluster-wide

4. Get Pods

kubectl get pods

List all running Pods and their status

beginner
NAME READY STATUS RESTARTS AGE\nmy-nginx-6d5f9c4b89-x4kzp 1/1 Running 0 1m
  • β€’-o wide shows node IP and node name
  • β€’--watch (-w) streams live updates

5. Describe a Resource

kubectl describe pod [pod-name]

Show detailed information about a Pod including events and error messages

beginner
kubectl describe [resource] [name]
kubectl describe pod my-nginx-6d5f9c4b89-x4kzp
  • β€’This is your #1 debugging tool
  • β€’The 'Events' section at the bottom shows WHY a pod failed
  • β€’Also works: kubectl describe deployment my-nginx

6. View Logs

kubectl logs [pod-name]

Print the logs from a container in a Pod

beginner
kubectl logs my-nginx-6d5f9c4b89-x4kzp
  • β€’-f = follow (live stream)
  • β€’--previous = logs from the crashed previous container
  • β€’-c [container-name] if the Pod has multiple containers

7. Execute a Command Inside a Pod

kubectl exec -it [pod-name] -- /bin/sh

Open an interactive shell inside a running container

beginner
kubectl exec -it my-nginx-6d5f9c4b89-x4kzp -- /bin/sh
  • β€’-it = interactive terminal
  • β€’Use /bin/bash if the container has bash
  • β€’Exit with 'exit' or Ctrl+D

8. Scale a Deployment

kubectl scale deployment my-nginx --replicas=5

Change the number of running Pod replicas instantly

beginner
deployment.apps/my-nginx scaled
  • β€’Scale to 0 to stop all Pods without deleting the Deployment
  • β€’Kubernetes adds/removes Pods within seconds

9. Port Forward (Local Access)

kubectl port-forward pod/[pod-name] 8080:80

Forward a local port to a port on a Pod (for testing)

beginner
kubectl port-forward pod/my-nginx-6d5f9c4b89-x4kzp 8080:80
  • β€’Open http://localhost:8080 to access the Pod directly
  • β€’Also works with services: kubectl port-forward svc/my-nginx-svc 8080:80
  • β€’Press Ctrl+C to stop forwarding

10. Delete a Resource

kubectl delete -f my-deployment.yaml

Delete all resources defined in a YAML file

beginner
deployment.apps/my-nginx deleted
  • β€’Preferred over kubectl delete deployment my-nginx (matches what you created)
  • β€’Kubernetes gracefully stops Pods before deleting

Troubleshooting: Common Pod Statuses

StatusMeaningWhat To Do
PendingNo node has enough CPU/RAMCheck kubectl describe pod for resource errors
CrashLoopBackOffApp crashes immediately on startkubectl logs --previous [pod] to see the crash reason
ImagePullBackOffCan’t download the container imageCheck image name spelling and registry access
OOMKilledContainer exceeded its memory limitIncrease resources.limits.memory in your YAML
Terminating (stuck)Pod won’t delete cleanlykubectl delete pod [name] --force --grace-period=0

Hands-On Challenge: Deploy Your First App

Mission: Run Nginx in Kubernetes

Deploy a 3-replica Nginx app and access it from your browser.

Step 1: Start minikube

minikube start --driver=docker

Step 2: Create your deployment YAML (save as nginx-deploy.yaml)

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

Step 3: Apply it

kubectl apply -f nginx-deploy.yaml

Step 4: Verify 3 Pods are Running

kubectl get pods

Step 5: Access it via port-forward

kubectl port-forward deployment/nginx-app 8080:80

Open http://localhost:8080 β€” you should see the Nginx welcome page!

Step 6: Scale to 5 replicas

kubectl scale deployment nginx-app --replicas=5
kubectl get pods --watch

Quiz: Test Your Knowledge

🧠

Test Your Knowledge

Take a quick 4-question quiz to check your understanding.


Key Takeaways

  1. Kubernetes orchestrates containers β€” it’s the Conductor for your entire application.
  2. Control Plane manages state; Worker Nodes run workloads.
  3. Pods are ephemeral; Deployments keep them alive and at the right replica count.
  4. Services give Pods stable, load-balanced networking.
  5. kubectl apply -f is how you deploy; kubectl describe + kubectl logs is how you debug.
You Now Know

The Conductor (Kubernetes) ensures your application keeps playing, no matter what happens to the musicians. And you can now direct that orchestra with kubectl!

Next Steps

Found this helpful? Explore more in the Containers Hub!

πŸ“§

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free
Type to start searching...