4 Hours

19. Docker and Kubernetes: The Industry Standard

Ecosystem

From Docker to Kubernetes

Kubernetes (K8s) is the industry standard for container orchestration. While Swarm is simpler and built into Docker, Kubernetes has become the dominant platform for large-scale production deployments. This module bridges your Docker knowledge to Kubernetes concepts.

Kubernetes Concepts: Mapping from Docker

Kubernetes takes Docker concepts and adds layers of abstraction for scale. A Pod is the smallest deployable unit — it's like a `docker run` but can contain multiple containers that share the same network namespace. A Deployment manages Pod replicas, rolling updates, and rollbacks — similar to a Swarm service. A Service provides stable networking and load balancing — like Swarm's routing mesh. A ConfigMap holds configuration data — like environment variables but more structured. A Secret holds sensitive data — similar to Docker Secrets but more integrated. PersistentVolume and PersistentVolumeClaim manage storage — like Docker volumes but cluster-wide.

Text
Docker Concept              Kubernetes Equivalent
─────────────────────────────────────────────────────────
docker run                  Pod + Container spec
docker-compose.yml          Deployment + Service
docker network              NetworkPolicy / Service
docker volume               PersistentVolumeClaim
docker swarm init           Control Plane + Nodes
docker service              Deployment with replicas
docker secrets              Secret
docker config               ConfigMap

Running Kubernetes Locally: Minikube and kind

For learning, run Kubernetes on your local machine. Minikube creates a single-node cluster inside a VM or container. kind (Kubernetes in Docker) runs a cluster using Docker containers as nodes — faster to start, great for CI. Docker Desktop also includes a built-in Kubernetes cluster. These local clusters let you test your manifest files without needing cloud infrastructure.

Bash
# Enable Kubernetes in Docker Desktop
# Settings → Kubernetes → Enable Kubernetes

# Install minikube
brew install minikube  # macOS
choco install minikube  # Windows
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64  # Linux

# Start minikube
minikube start --driver=docker

# Install kind
go install sigs.k8s.io/kind@latest

# Create cluster with kind
kind create cluster --name dev

# Verify cluster
kubectl cluster-info
kubectl get nodes

Deploying Your Docker Image to Kubernetes

Once your Docker image is in a registry, you can deploy it to Kubernetes. A minimal deployment manifest defines the container image, number of replicas, and ports. A Service exposes the deployment to the network. The combination replaces your `docker run` and `docker service` commands with declarative YAML that Kubernetes reconciles.

Text
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: app
        image: myregistry/myapp:latest
        ports:
        - containerPort: 8080
        env:
        - name: NODE_ENV
          value: production
        resources:
          limits:
            memory: 512Mi
            cpu: 500m
          requests:
            memory: 256Mi
            cpu: 250m
---
apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  selector:
    app: myapp
  ports:
  - port: 80
    targetPort: 8080
  type: LoadBalancer
Bash
# Apply the deployment
kubectl apply -f deployment.yaml

# Check status
kubectl get pods
kubectl get deployments
kubectl get services

# Update with new image version
kubectl set image deployment/myapp app=myregistry/myapp:v2
kubectl rollout status deployment/myapp

# Roll back to previous version
kubectl rollout undo deployment/myapp

# Delete the deployment
kubectl delete -f deployment.yaml

Knowledge Check

Ready to test your understanding of 19. Docker and Kubernetes: The Industry Standard?

Back