Loading earlier articles…

Kubernetes Basics — Pods, Deployments & Services

The three Kubernetes objects you must understand first — pods, deployments, and services — explained with runnable YAML.

12 min read

Why Kubernetes?

Docker runs one container on one machine. Kubernetes runs thousands of containers across many machines — restarting them when they crash, scaling them when traffic spikes, and routing traffic between them.

The Big Three Objects

Before the YAML, here is what each object is actually for:

Object What it does You create it when
Pod Runs one or more containers together on a single node Almost never directly — a Deployment makes these for you
Deployment Keeps N identical pods running, replaces the ones that die You want your app to stay up and be scalable
Service Gives a stable DNS name and IP in front of changing pods Anything needs to reach your app
Ingress Routes external HTTP traffic to services by host and path You want a public URL with TLS

1. Pod — the smallest unit

apiVersion: v1
kind: Pod
metadata:
  name: my-app
spec:
  containers:
    - name: my-app
      image: my-app:1.0
      ports:
        - containerPort: 3000

2. Deployment — pods with superpowers

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: my-app:1.0

3. Service — stable networking

apiVersion: v1
kind: Service
metadata:
  name: my-app
spec:
  selector:
    app: my-app
  ports:
    - port: 80
      targetPort: 3000

Essential Commands

kubectl apply -f deployment.yaml
kubectl get pods
kubectl logs -f deployment/my-app
kubectl scale deployment my-app --replicas=5

Practice Task

Install minikube or kind locally, deploy the manifests above, and scale your app from 1 to 5 replicas while watching kubectl get pods -w.

Loading next article…