Kubernetes is the operating system of the cloudโand understanding it is essential for modern DevOps, SaaS, and full-stack development. Whether you're a beginner or looking to deepen your knowledge, this tutorial will walk you through every core concept with real-world examples.
๐ฆ What is Kubernetes?
Kubernetes (K8s) is an open-source container orchestration platform that helps you deploy, scale, and manage containerized applications.
Imagine running 100+ microservices. How do you keep them alive, ensure networking, balance traffic, and roll out updates safely? Thatโs what Kubernetes automates.
๐ง Why Use Kubernetes?
- ๐ Auto-scaling and load balancing
- ๐ Self-healing (crash recovery, restart)
- ๐ ๏ธ Rolling updates with zero downtime
- ๐ Secrets & configuration management
- ๐๏ธ Persistent storage
- ๐ Ingress + traffic routing
- ๐งฑ Infrastructure-as-Code (YAML)
๐ ๏ธ Kubernetes Core Components (Visualized)
| Component | Description |
|---|---|
| Pod | Smallest unit in K8s. Runs 1+ containers. |
| Deployment | Manages pods & versions over time. |
| Service | Exposes your pods within/outside the cluster. |
| Ingress | Manages HTTP/HTTPS routing to services. |
| ConfigMap | Externalizes config data (non-sensitive). |
| Secret | Injects sensitive data (passwords, tokens). |
| PVC | Persistent storage requests for stateful apps. |
| Node | A VM or physical machine in the cluster. |
๐งฑ Hands-On: Create a Complete K8s App Stack
We'll now walk through creating:
- A simple Node.js app
- A Deployment to manage it
- A Service to expose it
- A ConfigMap and Secret
- A PersistentVolumeClaim
๐ Step 1: deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 2
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: node:18
command: ["node", "-e", "require('http').createServer((_,res)=>res.end('Hi')).listen(3000)"]
ports:
- containerPort: 3000
โ What it does:
- Launches 2 pods of a Node.js app
- Uses node:18 as base image
- Exposes port 3000 inside the container
๐ Step 2: service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
type: NodePort
selector:
app: my-app
ports:
- port: 80
targetPort: 3000
nodePort: 30080
โ What it does:
- Makes the app available via port
30080on your node - Load-balances between the pods
- Accepts requests on port
80, routes to3000
โ๏ธ Step 3: configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_ENV: production
โ What it does:
- Stores non-sensitive environment variables
- Can be injected into your pod like this:
envFrom:
- configMapRef:
name: app-config
๐ Step 4: secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: db-secret
type: Opaque
data:
DB_PASSWORD: bXlTZWNyZXRQYXNz
โ What it does:
- Encodes secrets in base64 (e.g.
mySecretPass) - You can inject it in your pod:
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: DB_PASSWORD
๐พ Step 5:pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
โ What it does:
- Requests 1 GB of storage
- You can mount it into your pod at
/data:
volumes:
- name: storage
persistentVolumeClaim:
claimName: my-pvc
volumeMounts:
- name: storage
mountPath: /data
๐ Running Everything
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f configmap.yaml
kubectl apply -f secret.yaml
kubectl apply -f pvc.yaml
๐ Bonus: Useful K8s Commands
kubectl get pods
kubectl get svc
kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl delete -f deployment.yaml
โค๏ธ Support & Follow
If you found this helpful:
- ๐ง Follow me for more DevOps + Cloud tutorials
- ๐ฌ Comment your Kubernetes use-case
- โญ Save this post for later

Top comments (0)