βΈοΈ Kubernetes Intro
Manage many containers at once. Scale your app automatically.
π What is Kubernetes?
Kubernetes (often called K8s) is a tool that manages many Docker containers. It decides where each container runs, restarts them if they crash, and scales them up or down when traffic changes.
Imagine you have a pizza shop. One chef (Docker container) can only make so many pizzas. Kubernetes is the manager who hires more chefs when it gets busy and sends them home when it is quiet.
π€ Why Use Kubernetes?
- Self-healing: If a container crashes, Kubernetes starts a new one.
- Scaling: Add more containers when traffic is high.
- Load balancing: Spread traffic across all containers.
- Rolling updates: Update your app with zero downtime.
- Works anywhere: AWS, Azure, Google Cloud, or your own server.
π Real Client Example
Client: A ticket-selling website for concerts.
Problem: When a popular concert goes on sale, 100,000 people visit at once. The single server crashes.
Solution with Kubernetes:
- Kubernetes notices the high traffic.
- It starts 20 more containers in seconds.
- Traffic is spread across all containers.
- When the sale ends, it shuts down extra containers.
Result: The site stays online. The client sells all tickets. No crashes.
π Key Concepts
| Word | Simple Meaning |
|---|---|
| Pod | The smallest unit. Usually one container. |
| Node | A worker machine (physical or virtual). |
| Cluster | A group of nodes managed by Kubernetes. |
| Deployment | Tells Kubernetes how many pods to run. |
| Service | Gives pods a stable address. |
| Ingress | Routes outside traffic to services. |
βοΈ Your First Kubernetes File
This YAML file tells Kubernetes to run 3 copies of your app:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:latest
ports:
- containerPort: 80
What this does:
replicas: 3β Run 3 copies of the app.image: myapp:latestβ Use your Docker image.containerPort: 80β The app listens on port 80.
β¨οΈ Basic kubectl Commands
| Command | What It Does |
|---|---|
kubectl apply -f app.yaml | Create or update resources. |
kubectl get pods | List all pods. |
kubectl get services | List all services. |
kubectl logs <pod-name> | See logs from a pod. |
kubectl delete -f app.yaml | Delete resources. |
β What You Learned
- Kubernetes manages many Docker containers.
- It self-heals, scales, and balances traffic.
- Pods, nodes, clusters, deployments, and services are the key words.
- You use kubectl to manage Kubernetes.