Back to Cloud & DevOps

Module 4: Kubernetes Orchestration

Orchestrate containers at scale with the industry-standard platform

🎼 What is Kubernetes?

Imagine an orchestra with 100 musicians. Without a conductor, it would be chaos! Kubernetes (K8s) is like that conductor for containers. It manages hundreds or thousands of containers, ensuring they work together harmoniously - starting, stopping, scaling, and healing them automatically.

The Problem Kubernetes Solves

Docker is great for running containers, but what happens when you have 100 containers across 10 servers? How do you deploy updates? Handle failures? Scale automatically? Kubernetes automates all of this!

Why Kubernetes?

Auto-scaling

Automatically scale based on CPU, memory, or custom metrics

Self-healing

Automatically restart failed containers

Load Balancing

Distribute traffic across containers automatically

Rolling Updates

Deploy new versions with zero downtime

🏗️ Kubernetes Architecture

Kubernetes uses a master-worker architecture. The master (control plane) makes decisions, and workers (nodes) run your containers.

Control Plane (Master)

  • API Server: Front-end for K8s
  • Scheduler: Assigns pods to nodes
  • Controller Manager: Maintains desired state
  • etcd: Key-value store for cluster data

Worker Nodes

  • Kubelet: Agent running on each node
  • Container Runtime: Docker, containerd
  • Kube-proxy: Network proxy
  • Pods: Your running containers

🔑 Core Kubernetes Concepts

Pod

Smallest deployable unit. Usually one container, but can be multiple tightly coupled containers. Like a pea pod - containers inside share network and storage.

Deployment

Manages a set of identical pods. Handles rolling updates, rollbacks, and scaling. Declares desired state, K8s makes it happen!

Service

Stable network endpoint for pods. Pods come and go, but services provide consistent access. Like a phone number that always reaches you, even if you change phones.

ConfigMap & Secret

Store configuration and sensitive data separately from code. ConfigMaps for non-sensitive config, Secrets for passwords and keys.

# Example Deployment YAML

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.14.2

ports:

- containerPort: 80

⚙️ Essential kubectl Commands

kubectl is your command-line tool for Kubernetes. Like a remote control for your cluster!

# Get cluster info

kubectl cluster-info

# List all pods

kubectl get pods

# Create deployment

kubectl apply -f deployment.yaml

# Scale deployment

kubectl scale deployment nginx --replicas=5

# View logs

kubectl logs pod-name

# Execute command in pod

kubectl exec -it pod-name -- /bin/bash

# Delete resources

kubectl delete -f deployment.yaml

📚 Learning Resources

Official Resources

Practice

🎯 What's Next?

Great work! You now understand Kubernetes orchestration. Next, we'll learn CI/CD pipelines to automate building, testing, and deploying your applications. Get ready to ship code faster!