🌩️ Lab Environment on Amazon Web Services using Amazon EC2

CPU   → 2–4 cores
RAM   → 4–6 GB
Disk  → 30–40 GB

Create:
  • Ubuntu 22.04

  • t2.medium

  • SSH login

ssh ubuntu@<ip>


πŸ”Ή STEP 1 — Install Docker

✅ Why?

Minikube runs Kubernetes inside Docker containers

sudo apt update sudo apt install docker.io -y sudo systemctl enable docker sudo systemctl start docker sudo usermod -aG docker $USER newgrp docker

Check:

docker ps

πŸ‘‰ works = good



πŸ”Ή STEP 2 — Install kubectl

✅ Why?

kubectl = control Kubernetes cluster

sudo snap install kubectl --classic kubectl version --client


πŸ”Ή STEP 3 — Install Minikube

πŸ€” Why Minikube is necessary?

Before Minikube:
❌ need 3–5 servers
❌ costly
❌ complex

With Minikube:
✅ single node cluster
✅ local testing
✅ fast learning
✅ safe experiments

πŸ‘‰ Think:

Minikube = practice ground EKS/Prod = real battlefield

Install:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 chmod +x minikube-linux-amd64 sudo mv minikube-linux-amd64 /usr/local/bin/minikube

Start:

minikube start --driver=docker

Check:

kubectl get nodes

Observe:

minikube Ready

πŸŽ‰ Cluster ready



🧠 Now Kubernetes Objects (one by one)


πŸ“¦ POD

✅ What?

Smallest deployable unit

✅ Why?

Container cannot run alone → must be inside Pod

Think:

Docker container = engine Pod = vehicle

Commands

kubectl run nginx --image=nginx --restart=Never kubectl get pods kubectl describe pod nginx kubectl logs nginx kubectl delete pod nginx

Observe

Create → Running
Delete → Gone permanently

❌ No self-healing


Learning

Pod = testing only
Not production



πŸ” REPLICASET

✅ What?

Keeps fixed number of Pods

✅ Why?

If server crashes → auto recreate


Commands

kubectl create deployment nginx-rs --image=nginx --replicas=3 kubectl get pods

Delete one:

kubectl delete pod <name>

Observe:
πŸ‘‰ new pod auto-created


Learning

ReplicaSet = self-healing



πŸš€ DEPLOYMENT

✅ What?

Manages ReplicaSets

✅ Why?

Because we need:
✅ rolling update
✅ rollback
✅ scaling

ReplicaSet cannot update safely


Commands

kubectl create deployment nginx --image=nginx kubectl scale deployment nginx --replicas=5 kubectl get pods -w

Observe:
pods 1 → 5


Update:

kubectl set image deployment/nginx nginx=nginx:latest kubectl rollout status deployment nginx

Rollback:

kubectl rollout undo deployment nginx

Learning

Deployment = production controller



πŸ“Š METRICS SERVER

✅ What?

Collects:

  • CPU

  • Memory

✅ Why?

Required for:

  • kubectl top

  • HPA

Without metrics → no autoscaling


Install

minikube addons enable metrics-server

Check:

kubectl top nodes kubectl top pods

Observe:
CPU/memory values



⚡ HPA (Horizontal Pod Autoscaler)

✅ What?

Auto increase/decrease pods

✅ Why?

Traffic changes daily

Without HPA:
❌ waste money
❌ app crashes

With HPA:
✅ scale automatically
✅ cost efficient


πŸ”₯ How to do HPA (step-by-step)

Step 1 — Create deployment first

kubectl create deployment nginx --image=nginx

Step 2 — Attach autoscaler

kubectl autoscale deployment nginx --cpu-percent=50 --min=2 --max=10

Step 3 — Monitor continuously

Open 3 terminals:

T1

kubectl get hpa -w

T2

kubectl get pods -w

T3 generate load

kubectl run -it load --image=busybox -- sh

Inside:

while true; do wget -q -O- http://nginx; done

Observe

Pods:

2 → 4 → 7 → 10

Stop load:

10 → 5 → 2

Commands to repeatedly check

kubectl get hpa kubectl describe hpa nginx kubectl top pods kubectl get deploy kubectl get pods -w

Learning

Metrics → HPA → Deployment → Pods scale



πŸ–₯️ DAEMONSET

✅ What?

Runs 1 pod on every node

✅ Why?

Some apps must run everywhere

Examples:

  • logging

  • monitoring

  • security agents


Commands

kubectl create daemonset ds-nginx --image=nginx kubectl get pods -o wide

Observe:
1 pod per node


Learning

DaemonSet = node-level service



🎨 kubecolor

Why?

Better readability

Install:

sudo apt install kubecolor -y alias kubectl=kubecolor

Now outputs colorful



🧠 FINAL BIG PICTURE (memory trick)

Minikube → cluster Pod → run container ReplicaSet → maintain count Deployment → update safely Metrics → measure usage HPA → scale automatically DaemonSet → run everywhere kubecolor → readable CLI

You’ve basically covered 80% of real Kubernetes used in companies already πŸ˜„πŸ”₯

Comments

Popular posts from this blog

Managing Amazon EBS Volumes and Snapshots Across Regions

Git for Beginners: Complete Guide from Installation to First Push on GitHub

AWS - Amazon Web Services