التخطي إلى المحتوى الرئيسي

What is Kubernetes | Explain Kubernetes in depth

 

1. What is Kubernetes? (K8s)

  • Definition:
    Kubernetes (often written as K8s) is an open-source container orchestration platform.
    It automates the deployment, scaling, and management of containerized applications.

  • Why we need it:
    If you run just 1 container, Docker is enough.
    But in real projects, we run tens or hundreds of containers across multiple servers.
    Problems arise:

    • How to restart a failed container automatically?

    • How to scale containers up/down?

    • How to update apps without downtime?

    • How to expose services to the outside world?

    Kubernetes solves all of these by acting like a “container manager” for the whole cluster.

  • Key features:

    1. Container Scheduling → Decides on which node a container should run.

    2. Self-healing → Restarts failed containers automatically.

    3. Scaling → Increases or decreases the number of containers based on demand.

    4. Rolling Updates & Rollbacks → Updates apps without downtime.

    5. Service Discovery & Load Balancing → Distributes traffic to the right containers.

  • Real-life analogy:
    Think of Kubernetes like an airport traffic control system — instead of planes and runways, it manages containers and servers to make sure everything runs safely and efficiently.


2. What is kubectl?

  • Definition:
    kubectl (pronounced cube-control or kube-cuddle) is the command-line tool used to interact with a Kubernetes cluster.

  • Purpose:
    It sends commands (using Kubernetes API) to manage resources such as pods, deployments, and services.

  • Common examples:

    bash

    kubectl get pods # List pods kubectl describe pod xyz # Detailed info of a pod kubectl apply -f file.yml # Create/update resources from a YAML file kubectl delete pod xyz # Delete a pod
  • Analogy:
    If Kubernetes is a restaurant kitchen, kubectl is the waiter taking orders from customers (you) and passing them to the chef (K8s) to execute.


3. What is Minikube?

  • Definition:
    Minikube is a tool that lets you run a single-node Kubernetes cluster locally on your laptop.

  • Purpose:
    It’s perfect for:

    • Learning Kubernetes

    • Testing small workloads

    • Running labs without using cloud services (AWS/GCP/Azure)

  • How it works:

    • It creates a virtual machine or container on your system.

    • Installs Kubernetes inside it.

    • Lets you access it with kubectl.

  • Key features:

    • Runs Kubernetes locally in minutes.

    • Has add-ons like Ingress, metrics-server, dashboard.

    • Supports multiple drivers (Docker, Hyper-V, VirtualBox, etc.).

  • Analogy:
    If Kubernetes in production is a big city, Minikube is a miniature model of that city — great for learning and experiments.


4. How these three fit together

  1. Minikube → Creates your local Kubernetes cluster.

  2. Kubernetes → The platform running your containers inside that cluster.

  3. kubectl → The remote control to interact with Kubernetes.

Flow:
You → run command in kubectl → sends request to Kubernetes API Server in Minikube → Kubernetes manages your containers.

0) Prereqs (Windows 10/11)


Hardware virtualization ON in BIOS.


Admin PowerShell.


Optional but recommended: WSL2 + Ubuntu (wsl --install in admin PowerShell, reboot).


Install kubectl (one of):


winget install -e --id Kubernetes.kubectl


choco install kubernetes-cli


scoop install kubectl

Verify: kubectl version --client. 

Kubernetes


1) Choose ONE local cluster

A) Docker Desktop (simplest)


Install Docker Desktop (Windows).


Open Settings → Kubernetes → Enable Kubernetes → Apply & Restart.

Wait until status shows Running. Docker also ships a kubectl on PATH. 

Docker Documentation

Docker


B) Minikube (very popular for learning)


Install Docker Desktop or enable Hyper-V (Win Pro/Enterprise):

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All (reboot). 

minikube


Start a cluster (pick a driver):


With Docker driver (works on Win Home via WSL2):

minikube start --driver=docker


With Hyper-V (Win Pro/Enterprise):

minikube start --driver=hyperv

You can set a default driver: minikube config set driver docker (or hyperv). 

minikube

+2

minikube

+2


Tip: If you like ultra-light clusters inside WSL2, kind (Kubernetes-in-Docker) is great: choco install kind → kind create cluster (run inside WSL2). 

Kind

+1


Verify your cluster (for any option):


kubectl cluster-info

kubectl get nodes


Create First Kubernate Apps:

1) Create folder k8s-lab or anyname

1) create two file deployment.yaml and service.yaml file


code of deployment.yaml file


apiVersion: apps/v1

kind: Deployment

metadata:

  name: my-app-deployment

spec:

  replicas: 2              # Number of pods

  selector:

    matchLabels:

      app: my-app

  template:

    metadata:

      labels:

        app: my-app

    spec:

      containers:

      - name: my-app-container

        image: nginx:latest   # Your app image

        ports:

        - containerPort: 80


code of service.yaml file

apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  type: NodePort         # Expose service on Node’s IP at a static port
  selector:
    app: my-app          # Match pods from Deployment
  ports:
  - port: 80             # Service port
    targetPort: 80       # Container port
    nodePort: 30007      # External port (between 30000-32767)


minikube start
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl get pods
kubectl get svc

minikube service my-app-service



🌍 Real-World Example: "TechForest App"

📂 Project Structure (Windows)

Create a folder (e.g., C:\node-k8s-app) and inside put:

C:\node-k8s-app ├── server.js ├── package.json └── Dockerfile

1) package.json

{ "name": "node-k8s-app", "version": "1.0.0", "main": "server.js", "scripts": { "start": "node server.js" }, "dependencies": { "express": "^4.19.2" } }

2) server.js

const express = require("express"); const app = express(); const PORT = process.env.PORT || 3000; app.get("/", (req, res) => { res.send("🚀 Hello from Node.js + Express + Kubernetes on Windows!"); }); app.get("/health", (req, res) => { res.status(200).json({ status: "ok" }); }); app.listen(PORT, () => { console.log(`App running on port ${PORT}`); });

3) Dockerfile

FROM node:20-alpine WORKDIR /usr/src/app COPY package*.json ./ RUN npm install --only=production COPY . . EXPOSE 3000 CMD ["npm", "start"]

4) Build & Load Docker Image into Minikube (Windows)

Option A: Use Minikube’s image builder (recommended)

In PowerShell (in your project folder):

minikube image build -t node-k8s-app:1.0 .

Option B: Use Docker inside Minikube

Enable Docker daemon inside Minikube:

minikube docker-env | Invoke-Expression docker build -t node-k8s-app:1.0 . minikube docker-env -u | Invoke-Expression

5) Kubernetes YAML

Save this as node-app.yaml in C:\node-k8s-app\

apiVersion: v1 kind: Namespace metadata: name: demo --- apiVersion: apps/v1 kind: Deployment metadata: name: node-app-deployment namespace: demo labels: app: node-app spec: replicas: 2 selector: matchLabels: app: node-app template: metadata: labels: app: node-app spec: containers: - name: node-app image: node-k8s-app:1.0 imagePullPolicy: IfNotPresent ports: - containerPort: 3000 readinessProbe: httpGet: path: /health port: 3000 initialDelaySeconds: 5 periodSeconds: 5 livenessProbe: httpGet: path: /health port: 3000 initialDelaySeconds: 15 periodSeconds: 10 --- apiVersion: v1 kind: Service metadata: name: node-app-service namespace: demo spec: type: NodePort selector: app: node-app ports: - port: 3000 targetPort: 3000 nodePort: 30080

6) Deploy to Minikube

Run in PowerShell:

kubectl apply -f node-app.yaml kubectl get pods -n demo kubectl rollout status deployment/node-app-deployment -n demo

7) Access the App

Option A: Open via Minikube

minikube service node-app-service -n demo --url

Option B: Port-forward

kubectl port-forward svc/node-app-service -n demo 8080:3000

👉 Visit: http://localhost:8080


8) Test Endpoints

  • http://localhost:8080/ → 🚀 Hello from Node.js + Express + Kubernetes on Windows!

  • http://localhost:8080/health{ "status": "ok" }

تعليقات

المشاركات الشائعة من هذه المدونة

DSA in C# | Data Structure and Algorithm using C#

  DSA in C# |  Data Structure and Algorithm using C#: Lecture 1: Introduction to Data Structures and Algorithms (1 Hour) 1.1 What are Data Structures? Data Structures are ways to store and organize data so it can be used efficiently. Think of data structures as containers that hold data in a specific format. Types of Data Structures: Primitive Data Structures : These are basic structures built into the language. Example: int , float , char , bool in C#. Example : csharp int age = 25;  // 'age' stores an integer value. bool isStudent = true;  // 'isStudent' stores a boolean value. Non-Primitive Data Structures : These are more complex and are built using primitive types. They are divided into: Linear : Arrays, Lists, Queues, Stacks (data is arranged in a sequence). Non-Linear : Trees, Graphs (data is connected in more complex ways). Example : // Array is a simple linear data structure int[] number...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025

 Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025 Now a days most of the IT Company asked NODE JS Question mostly in interview. I am creating this article to provide help to all MERN Stack developer , who is in doubt that which type of question can be asked in MERN Stack  then they can learn from this article. I am Shiva Gautam,  I have 15 Years of experience in Multiple IT Technology, I am Founder of Shiva Concept Solution Best Programming Institute with 100% Job placement guarantee. for more information visit  Shiva Concept Solution 1. What is the MERN Stack? Answer : MERN Stack is a full-stack JavaScript framework using MongoDB (database), Express.js (backend framework), React (frontend library), and Node.js (server runtime). It’s popular for building fast, scalable web apps with one language—JavaScript. 2. What is MongoDB, and why use it in MERN? Answer : MongoDB is a NoSQL database that stores data in flexible, JSON-like documents. It...