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

Lav kushwahaLav kushwaha
6 min read

๐Ÿง  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

FeatureBenefit
Auto-healingRestarts crashed containers
ScalabilityHorizontal scaling of services easily
Load balancingDistributes network traffic efficiently
Rollback/UpdateZero downtime deployments
Infrastructure agnosticRuns 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:

  1. API Server (kube-apiserver)

    • Entry point for all REST commands (kubectl, UI, etc.)

    • Communicates with all components

  2. Controller Manager (kube-controller-manager)

    • Monitors cluster state (e.g., restarts pods if they crash)

    • Manages replication, endpoints, nodes, etc.

  3. Scheduler (kube-scheduler)

    • Decides which worker node will run a pod

    • Based on CPU, memory, etc.

  4. 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:

  1. Kubelet

    • Talks to the API server

    • Ensures the pod is running as expected on this node

  2. Kube Proxy

    • Handles networking

    • Forwards traffic to correct pod

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

  1. You write a deployment YAML or use kubectl apply.

  2. API Server receives the request.

  3. Scheduler selects a worker node.

  4. Kubelet on that node starts the pod.

  5. Pod runs your container.


๐Ÿ“Œ Summary Table

ComponentRole
ClusterEntire K8s setup
Master NodeManages the cluster
Worker NodeRuns the pods
PodSmallest unit running container(s)
KubeletEnsures pod health
Kube ProxyNetworking
etcdStores all cluster data
SchedulerPicks the right node
API ServerControl 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

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

CommandDescription
kubectl cluster-infoShow cluster details
kubectl get nodesList nodes
kubectl get podsList 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> -- bashTerminal inside pod
kubectl get allShow 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

FeatureBenefit
Declarative SyntaxEasier to manage and repeat
Version ControlledCan be saved in Git
Automation-FriendlyWorks with CI/CD tools
ReusableDefine 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

ToolUse
MinikubeEasiest way to run K8s locally (VM-based)
KindLightweight Kubernetes cluster in Docker
kubectlCLI to interact with K8s
~/.kube/configKubeconfig to manage clusters
YAML (manifest)Define and manage resources
kubectl proxyExpose Kubernetes API locally
0
Subscribe to my newsletter

Read articles from Lav kushwaha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Lav kushwaha
Lav kushwaha