DevOpsintermediate12 min read

Kubernetes Core Concepts

Learn the building blocks of Kubernetes: pods, deployments, services, and namespaces. Understand how K8s orchestrates containers at scale.

What Kubernetes Solves

Docker runs containers on a single machine. Kubernetes runs them across a cluster of machines, handling:

  • Scheduling — deciding which node runs each container
  • Scaling — adding/removing replicas based on load
  • Self-healing — restarting failed containers automatically
  • Service discovery — letting containers find each other
  • Rolling updates — deploying new versions with zero downtime

Pods

A pod is the smallest deployable unit — one or more containers that share network and storage. In practice, most pods run a single container.

apiVersion: v1
kind: Pod
metadata:
  name: web
  labels:
    app: web
spec:
  containers:
    - name: app
      image: myapp:latest
      ports:
        - containerPort: 3000

Deployments

A deployment manages a set of identical pods. It handles scaling, rolling updates, and rollbacks. You almost never create pods directly — use deployments instead.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: app
          image: myapp:v2
          ports:
            - containerPort: 3000
          resources:
            requests:
              memory: "128Mi"
              cpu: "100m"
            limits:
              memory: "256Mi"
              cpu: "500m"

Services

A service provides a stable network endpoint for a set of pods. Pods are ephemeral — they get new IPs when restarted. Services give them a consistent address.

  • ClusterIP — internal only (default)
  • NodePort — exposes on each node's IP at a static port
  • LoadBalancer — provisions a cloud load balancer
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  selector:
    app: web
  ports:
    - port: 80
      targetPort: 3000
  type: LoadBalancer

Essential kubectl Commands

These cover day-to-day cluster operations:

# Apply a manifest
kubectl apply -f deployment.yaml

# List pods with status
kubectl get pods -o wide

# View logs
kubectl logs -f deployment/web

# Scale a deployment
kubectl scale deployment/web --replicas=5

# Roll back a bad deployment
kubectl rollout undo deployment/web

# Exec into a running pod
kubectl exec -it web-abc123 -- /bin/sh

Related Tutorials