Kubernetes (K8s) is the industry standard for container orchestration. Whether you're deploying microservices, batch jobs, or AI workloads, mastering Kubernetes is essential for any DevOps engineer in 2026. This guide walks you through every concept from zero to a working cluster.

What is Kubernetes?

Kubernetes is an open-source platform that automates the deployment, scaling, and management of containerized applications. Originally developed by Google (based on their internal Borg system), it's now maintained by the Cloud Native Computing Foundation (CNCF).

Key Benefit: Kubernetes abstracts away the underlying infrastructure so you can treat your entire datacenter (or cloud) as a single compute resource.

Core Concepts

1. Pods

The smallest deployable unit in Kubernetes. A pod represents one or more containers that share storage, network, and a specification for how to run. In most cases, you'll run one container per pod.

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80

2. Deployments

A Deployment manages a set of identical pods, ensuring the desired number are running at all times. It handles rolling updates, rollbacks, and self-healing.

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

3. Services

Services provide stable network endpoints to access your pods. Since pods are ephemeral (they come and go), Services give you a consistent IP and DNS name.

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - port: 80
    targetPort: 80
  type: LoadBalancer

Setting Up Your First Cluster

Option A: Local Development with Minikube

Minikube runs a single-node Kubernetes cluster on your local machineโ€”perfect for learning.

# Install minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

# Start cluster
minikube start --driver=docker

# Check status
kubectl get nodes

Option B: Cloud Managed Kubernetes

For production, use a managed service from your cloud provider:

  • Amazon EKS โ€” AWS Elastic Kubernetes Service
  • Google GKE โ€” Google Kubernetes Engine
  • Azure AKS โ€” Azure Kubernetes Service
  • DigitalOcean DOKS โ€” Simple, cost-effective option

Essential kubectl Commands

# View cluster info
kubectl cluster-info

# List all pods
kubectl get pods

# List all services
kubectl get services

# View pod logs
kubectl logs <pod-name>

# Execute command inside a pod
kubectl exec -it <pod-name> -- /bin/bash

# Apply a configuration file
kubectl apply -f deployment.yaml

# Delete a resource
kubectl delete pod <pod-name>

Real-World Deployment Walkthrough

Let's deploy a complete web application with a frontend, backend API, and database:

Step 1: Create a Namespace

kubectl create namespace myapp

Step 2: Deploy PostgreSQL

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
  namespace: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:16
        env:
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-secret
              key: password
        ports:
        - containerPort: 5432

Step 3: Deploy the API

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  namespace: myapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
      - name: api
        image: myapp/api:v1
        env:
        - name: DATABASE_URL
          value: "postgresql://postgres:password@postgres:5432/myapp"
        ports:
        - containerPort: 3000

Monitoring & Debugging

# Watch pod status in real-time
kubectl get pods -w

# Describe a pod for detailed info
kubectl describe pod <pod-name>

# Check resource usage
kubectl top pods

# Port forwarding (for local testing)
kubectl port-forward svc/my-service 8080:80

Best Practices for Production

  • Resource Limits: Always set CPU/memory requests and limits
  • Health Checks: Implement liveness and readiness probes
  • Secrets Management: Use Kubernetes Secrets or external vaults
  • Horizontal Scaling: Configure HPA (Horizontal Pod Autoscaler)
  • Network Policies: Restrict traffic between pods
  • Rolling Updates: Use maxSurge and maxUnavailable for zero-downtime deploys
Pro Tip: Use kubens and kubectx to quickly switch between namespaces and contexts. These two tools will save you hours of typing.

Next Steps

Mastering Kubernetes is a journey. Start with Minikube, experiment with the examples above, and gradually move to more complex patterns like Helm charts, operators, and service meshes.

Check out our other DevOps guides: