6th Week :- Mastering Kubernetes: From Basics to Full Cluster Architecture

Table of contents
- ๐ง What is Kubernetes?
- ๐ Why do we use Kubernetes?
- ๐ Advantages of Kubernetes
- ๐งฑ Kubernetes Architecture (High Level)
- ๐ง Master Node (Now called Control Plane)
- ๐ ๏ธ Worker Node
- ๐ฆ What is a Pod?
- ๐งญ Flow of Kubernetes
- ๐ Summary Table
- ๐ Example Real-Life Analogy
- ๐งฉ Diagram Summary (Kubernetes Architecture)
- โ 1. Create Kubernetes Cluster Locally
- ๐ ๏ธ cluster.yml Example for Kind
- ๐ What is ~/.kube/config?
- ๐ Where to See Pod Info via API?
- ๐ง Common kubectl Commands
- ๐ฆ Create Pod using manifest.yml
- โ๏ธ Define Master and Worker Node in Kind
- ๐ง Benefits of Using Manifest/YAML for Pods
- ๐ก Example with Node Selector
- ๐ฅ Bonus: Useful Minikube Commands
- ๐ง Summary Table
๐ง What is Kubernetes?
Kubernetes (also known as K8s) is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications.
It was originally developed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF).
๐ Why do we use Kubernetes?
In modern DevOps or cloud-native environments, applications are split into small, independent containers (e.g., Docker). Managing containers manually becomes hard when:
There are hundreds/thousands of containers.
You need to handle scaling, failures, load balancing, etc.
So, Kubernetes helps by:
โ
Automating deployment and scaling
โ
Restarting crashed containers
โ
Rolling updates & rollbacks
โ
Service discovery and load balancing
โ
Managing secrets & configurations
๐ Advantages of Kubernetes
Feature | Benefit |
Auto-healing | Restarts crashed containers |
Scalability | Horizontal scaling of services easily |
Load balancing | Distributes network traffic efficiently |
Rollback/Update | Zero downtime deployments |
Infrastructure agnostic | Runs on any cloud or on-prem |
๐งฑ Kubernetes Architecture (High Level)
๐ Cluster
A Kubernetes cluster is a set of machines (nodes) that run containerized applications. It has:
Master Node(s) โ control and manage the cluster
Worker Nodes โ run the actual applications (pods)
๐ง Master Node (Now called Control Plane)
Control Plane manages the cluster and makes global decisions like:
Scheduling apps
Detecting failures
Managing cluster state
Components inside Master Node:
API Server (
kube-apiserver
)Entry point for all REST commands (kubectl, UI, etc.)
Communicates with all components
Controller Manager (
kube-controller-manager
)Monitors cluster state (e.g., restarts pods if they crash)
Manages replication, endpoints, nodes, etc.
Scheduler (
kube-scheduler
)Decides which worker node will run a pod
Based on CPU, memory, etc.
etcd
A key-value database
Stores all cluster state (config, secrets, node info)
๐ ๏ธ Worker Node
Worker nodes run your containers/pods.
Components inside Worker Node:
Kubelet
Talks to the API server
Ensures the pod is running as expected on this node
Kube Proxy
Handles networking
Forwards traffic to correct pod
Container Runtime
- Runs containers (Docker, containerd, CRI-O)
๐ฆ What is a Pod?
A Pod is the smallest deployable unit in Kubernetes.
It can contain one or more containers that share:
Network IP
Storage volumes
Lifecycle
๐ง Think of a pod like a wrapper around your container(s).
๐ Example:
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: myapp-container
image: node:20
ports:
- containerPort: 3000
This will create a pod with 1 Node.js container.
๐งญ Flow of Kubernetes
You write a deployment YAML or use
kubectl apply
.API Server receives the request.
Scheduler selects a worker node.
Kubelet on that node starts the pod.
Pod runs your container.
๐ Summary Table
Component | Role |
Cluster | Entire K8s setup |
Master Node | Manages the cluster |
Worker Node | Runs the pods |
Pod | Smallest unit running container(s) |
Kubelet | Ensures pod health |
Kube Proxy | Networking |
etcd | Stores all cluster data |
Scheduler | Picks the right node |
API Server | Control center |
๐ Example Real-Life Analogy
Think of Kubernetes as an Operating System for your data center.
Containers = Apps
Pods = Processes
Master = OS Kernel
Worker Node = CPU cores
๐งฉ Diagram Summary (Kubernetes Architecture)
Here's a basic illustration:
+--------------------+
| API Server |
+--------------------+
|
+----------------+------------------+
| | |
+----------------+ +----------------+ +------------------------+
| Controller Mgr | | Scheduler | | etcd (Cluster DB) |
+----------------+ +----------------+ +------------------------+
|
[Control Plane]
|
-------------------------------------------------
| | |
+---------------+ +---------------+ +---------------+
| Worker Node | | Worker Node | | Worker Node |
+---------------+ +---------------+ +---------------+
| Kubelet | | Kubelet | | Kubelet |
| Kube Proxy | | Kube Proxy | | Kube Proxy |
| Container(s) | | Container(s) | | Container(s) |
+---------------+ +---------------+ +---------------+
โ 1. Create Kubernetes Cluster Locally
Option 1: ๐ณ Using Minikube (Recommended for beginners)
Step-by-step (Linux):
# 1. Install Minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
# 2. Start cluster
minikube start
# 3. Check status
minikube status
Option 2: ๐งฑ Using Kind (Kubernetes IN Docker)
Step-by-step (Linux):
# 1. Install Kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
# 2. Create kind-cluster using config YAML
kind create cluster --config cluster.yml
# 3. Check cluster
kubectl cluster-info
๐ ๏ธ cluster.yml
Example for Kind
# cluster.yml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
โก๏ธ Save this file and run:
kind create cluster --config cluster.yml
๐ What is ~/.kube/config
?
It's the Kubeconfig file.
It stores credentials, cluster info, and context for
kubectl
to connect to your cluster.Location:
~/.kube/config
cat ~/.kube/config
Youโll see clusters, users, and contexts defined here.
๐ Where to See Pod Info via API?
You can access Kubernetes API using:
curl http://localhost:8001/api/v1/pods
(First run: kubectl proxy
)
Also:
kubectl get pods -A
๐ง Common kubectl
Commands
Command | Description |
kubectl cluster-info | Show cluster details |
kubectl get nodes | List nodes |
kubectl get pods | List pods |
kubectl describe pod <pod-name> | Pod details |
kubectl apply -f <file> | Apply YAML manifest |
kubectl delete -f <file> | Delete resource |
kubectl logs <pod-name> | Show logs |
kubectl exec -it <pod-name> -- bash | Terminal inside pod |
kubectl get all | Show all resources |
๐ฆ Create Pod using manifest.yml
โ
Sample pod.yml
# pod.yml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: myapp-container
image: nginx
ports:
- containerPort: 80
Run it:
kubectl apply -f pod.yml
kubectl get pods
kubectl describe pod myapp-pod
โ๏ธ Define Master and Worker Node in Kind
With Kind, define in cluster.yml
:
nodes:
- role: control-plane # Master Node
- role: worker # Worker 1
- role: worker # Worker 2
Kubernetes automatically schedules pods on worker nodes unless specified otherwise using node selectors or taints/tolerations.
๐ง Benefits of Using Manifest/YAML for Pods
Feature | Benefit |
Declarative Syntax | Easier to manage and repeat |
Version Controlled | Can be saved in Git |
Automation-Friendly | Works with CI/CD tools |
Reusable | Define once, deploy many times |
๐ก Example with Node Selector
Deploy pod only on worker node named "worker-node-1":
apiVersion: v1
kind: Pod
metadata:
name: worker-app
spec:
nodeSelector:
kubernetes.io/hostname: worker-node-1
containers:
- name: app
image: nginx
๐ฅ Bonus: Useful Minikube Commands
minikube dashboard # GUI dashboard
minikube ssh # Shell inside minikube node
minikube stop # Stop the cluster
minikube delete # Delete cluster
๐ง Summary Table
Tool | Use |
Minikube | Easiest way to run K8s locally (VM-based) |
Kind | Lightweight Kubernetes cluster in Docker |
kubectl | CLI to interact with K8s |
~/.kube/config | Kubeconfig to manage clusters |
YAML (manifest) | Define and manage resources |
kubectl proxy | Expose Kubernetes API locally |
Subscribe to my newsletter
Read articles from Lav kushwaha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
