๐ What is Kubernetes?
Kubernetes is an open-source container orchestration platform originally developed by Google (now maintained by the Cloud Native Computing Foundation - CNCF).
It automates the deployment, scaling, and management of containerized applications (like Docker containers).
๐ Think of Kubernetes as the "operating system for your data center/cloud" that manages all your containerized workloads.
๐ฐ๏ธ A Quick History
- 2014 → Google open-sourced Kubernetes.
- 2015 → Donated to CNCF.
- Inspired by Google’s internal system Borg, which ran containers at massive scale.
- Today, Kubernetes is the industry standard for container orchestration.
โ๏ธ Why Do We Need Kubernetes?
Containers (like Docker) are great but managing them at scale is hard:
- How do you restart a failed container?
- How do you scale up/down when traffic changes?
- How do you load-balance across containers?
- How do you roll out updates without downtime?
๐ Kubernetes solves all of this automatically.
๐งฉ Key Concepts in Kubernetes
1๏ธโฃ Cluster
A Kubernetes cluster consists of:
- Master Node (Control Plane) → Manages the cluster (scheduler, API server, controller).
- Worker Nodes → Where containers (Pods) actually run.
2๏ธโฃ Pod
The smallest deployable unit in Kubernetes.
A Pod wraps one or more containers (usually 1).
Example: A Pod could run a web server container + a logging sidecar container.
3๏ธโฃ Deployment
Defines the desired state of Pods (e.g., 3 replicas of Nginx). Kubernetes ensures the cluster always matches this state.
Example: If 1 Pod crashes, Deployment brings it back automatically.
4๏ธโฃ Service
Provides networking and load balancing for Pods. Since Pods are ephemeral (they come and go), a Service gives them a stable IP and DNS name.
5๏ธโฃ Ingress
Manages external access to Services (HTTP/HTTPS). Lets you expose apps to the internet with domain names, SSL, routing, etc.
6๏ธโฃ ConfigMaps & Secrets
- ConfigMap → Store configuration (key-value pairs).
- Secret → Store sensitive data (like API keys, passwords).
7๏ธโฃ Autoscaling
Horizontal Pod Autoscaler (HPA) → Increases/decreases Pod replicas based on CPU/memory usage.
๐ Example: Running Nginx in Kubernetes
nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
๐ Run:
kubectl apply -f nginx-deployment.yaml kubectl apply -f nginx-service.yaml
Now you have 3 replicas of Nginx running behind a load-balanced service.
๐ Advantages of Kubernetes
- Self-healing → Restarts failed containers, replaces Pods, reschedules workloads.
- Scalability → Auto-scales applications up or down.
- Portability → Works on any cloud (AWS, Azure, GCP) or on-prem.
- Load Balancing & Networking → Distributes traffic across Pods.
- Rolling Updates & Rollbacks → Deploy updates without downtime.
- Resource Efficiency → Optimizes CPU/memory usage.
- Ecosystem & Extensibility → Works with Helm charts, Operators, Service Meshes, etc.
๐ Real-World Use Cases
- Running microservices architectures.
- Hosting scalable web apps & APIs.
- CI/CD pipelines (Jenkins, GitLab runners on Kubernetes).
- Big Data & AI workloads (TensorFlow on K8s).
- Hybrid cloud strategy → Run the same workloads on-prem & cloud.
Essential kubectl CLI Commands ๐งต
๐ Basic Setup & Cluster Info
| Command |
Usage |
| kubectl version |
Show client and server version. |
| kubectl cluster-info |
Display cluster info. |
| kubectl config view |
View kubeconfig settings. |
| kubectl config use-context |
Switch to a different cluster context. |
๐ฆ Pods
| Command |
Usage |
| kubectl get pods |
List all pods in the current namespace. |
| kubectl get pods -A |
List pods across all namespaces. |
|
kubectl describe pod
|
Show details of a pod. |
|
kubectl logs
|
View logs of a pod. |
|
kubectl exec -it
-- sh
|
Access a pod's shell. |
๐ Deployments
| Command |
Usage |
| kubectl get deployments |
List deployments. |
kubectl create deployment --image=![]() |
Create a new deployment. |
| kubectl scale deployment --replicas= |
Scale a deployment. |
| kubectl rollout status deployment/ |
Check rollout status. |
| kubectl rollout undo deployment/ |
Rollback a deployment. |
๐ Services & Networking
| Command |
Usage |
| kubectl get services |
List all services. |
|
kubectl expose deployment
--port=
--type=NodePort
|
Expose a deployment as a service. |
| kubectl port-forward svc/ : |
Forward local port to service. |
๐ Config & Secrets
| Command |
Usage |
| kubectl get configmaps |
List all configmaps. |
| kubectl create configmap --from-literal=key=value |
Create configmap from literal values. |
| kubectl get secrets |
List secrets. |
| kubectl create secret generic --from-literal=key=value |
Create secret from literal values. |
๐ Namespace Management
| Command |
Usage |
| kubectl get namespaces |
List all namespaces. |
| kubectl create namespace |
Create a new namespace. |
| kubectl delete namespace |
Delete a namespace. |
๐งน Cleanup
| Command |
Usage |
|
kubectl delete pod
|
Delete a pod. |
| kubectl delete deployment |
Delete a deployment. |
| kubectl delete service |
Delete a service. |
| kubectl delete all --all |
Delete all resources in the namespace. |