🚀 Kubernetes Setup (Local)

🟢 Minikube


Start cluster
minikube start

Check

kubectl get nodes kubectl cluster-info

📦 POD

✅ What is Pod?

Smallest deployable unit in Kubernetes
Contains:

  • 1 or more containers

  • same network

  • same storage

✅ Why Pod?

Because containers cannot run directly, they must run inside Pods.


🔹 Pod Commands

kubectl get pods kubectl describe pod mypod kubectl logs mypod kubectl delete pod mypod kubectl exec -it mypod -- bash

🔹 Create Pod (quick)

kubectl run nginx --image=nginx --restart=Never

🔹 Pod YAML

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

🔹 Generate YAML automatically

kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml

🔁 REPLICASET

✅ What is ReplicaSet?

Ensures fixed number of pods always running

✅ Why?

If pod dies → auto recreate


🔹 Commands

kubectl get rs kubectl scale rs myrs --replicas=5 kubectl delete rs myrs

🔹 ReplicaSet YAML

apiVersion: apps/v1 kind: ReplicaSet metadata: name: nginx-rs spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx

🔹 Generate YAML

kubectl create rs nginx --image=nginx --dry-run=client -o yaml

🚀 DEPLOYMENT

✅ What is Deployment?

Manages ReplicaSets + updates

✅ Why?

✔ Rolling updates
✔ Rollback
✔ Zero downtime


🔹 Commands

kubectl get deploy kubectl scale deploy nginx --replicas=5 kubectl rollout status deploy nginx kubectl rollout undo deploy nginx kubectl set image deploy/nginx nginx=nginx:1.25

🔹 Deployment YAML

apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx

🔹 Generate YAML

kubectl create deployment nginx --image=nginx --dry-run=client -o yaml > deploy.yaml

📊 METRICS SERVER

✅ What is Metrics Server?

Collects:

  • CPU

  • Memory

for:

  • HPA

  • kubectl top


🔹 Install (Minikube)

minikube addons enable metrics-server

🔹 Test

kubectl top nodes kubectl top pods

⚡ HPA (Horizontal Pod Autoscaler)

What?

Auto scale pods based on CPU/memory

Flow

Deployment → Metrics Server → HPA → Auto scale

Yes bro 👇
👉 First create Deployment
👉 Then attach HPA


🔹 Command

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

🔹 Check

kubectl get hpa watch kubectl get pods

🔹 YAML

apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: nginx-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: nginx-deploy minReplicas: 2 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 50

🖥️ DAEMONSET

🔷 What is DaemonSet?

Runs 1 pod on every node

🔷 Why?

Used for:

  • logging

  • monitoring

  • agents

Examples:

  • fluentd

  • node exporter


🔹 Commands

kubectl get ds kubectl delete ds myds

🔹 YAML

apiVersion: apps/v1 kind: DaemonSet metadata: name: nginx-ds spec: selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx

🔹 Generate YAML

kubectl create daemonset nginx --image=nginx --dry-run=client -o yaml

🎨 kubecolor

🟢 kubecolor

Install

sudo apt install kubecolor

or

brew install kubecolor

Use

kubecolor get pods kubecolor get all

Alias

alias kubectl=kubecolor

Now all outputs colorful 😍


🧠 Quick Memory Trick

Remember this order:

Pod → ReplicaSet → Deployment → HPA → DaemonSet

👉 Pod = run
👉 RS = maintain count
👉 Deployment = updates
👉 HPA = scale
👉 DS = run everywhere

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