What is Kubernetes and what problems does it solve?
Quick Answer
Kubernetes is an open-source container orchestration platform that automates deploying, scaling, networking, and managing containerized applications across a cluster. It solves running containers at scale: self-healing (restarting failed pods), horizontal scaling, rolling updates/rollbacks, service discovery and load balancing, and declarative configuration. You describe desired state in YAML and Kubernetes continuously reconciles the cluster to match it.
Detailed Answer
Kubernetes (K8s) is an open-source container orchestration platform that automates deployment, scaling, and management of containerized applications.
Problems Kubernetes Solves:
- Container Management at Scale: Managing hundreds or thousands of containers manually is impossible
- High Availability: Ensures applications stay running even when containers or nodes fail
- Load Balancing: Distributes traffic across multiple container instances
- Auto-Scaling: Automatically scales applications based on demand
- Rolling Updates: Deploy new versions without downtime
- Service Discovery: Containers can find and communicate with each other
- Storage Orchestration: Manages persistent storage for stateful applications
- Self-Healing: Automatically restarts failed containers
Kubernetes Architecture:
Control Plane Components:
- API Server: Frontend for Kubernetes control plane
- etcd: Distributed key-value store for cluster data
- Scheduler: Assigns pods to nodes
- Controller Manager: Runs controller processes
Node Components:
- Kubelet: Agent that runs on each node
- Container Runtime: Docker, containerd, etc.
- Kube-proxy: Network proxy on each node
Key Kubernetes Objects:
1. Pod - Smallest deployable unit (one or more containers)
apiVersion: v1
kind: Pod
metadata:
name: myapi-pod
spec:
containers:
- name: myapi
image: myapi:v1
ports:
- containerPort: 80
2. Deployment - Manages ReplicaSets and rolling updates
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapi-deployment
spec:
replicas: 3
selector:
matchLabels:
app: myapi
template:
metadata:
labels:
app: myapi
spec:
containers:
- name: myapi
image: myapi:v1
ports:
- containerPort: 80
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Production"
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /health
port: 80
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5
3. Service - Exposes pods to network traffic
apiVersion: v1
kind: Service
metadata:
name: myapi-service
spec:
type: LoadBalancer
selector:
app: myapi
ports:
- protocol: TCP
port: 80
targetPort: 80
4. ConfigMap - Stores configuration data
apiVersion: v1
kind: ConfigMap
metadata:
name: myapi-config
data:
appsettings.json: |
{
"Logging": {
"LogLevel": {
"Default": "Information"
}
}
}
5. Secret - Stores sensitive data
apiVersion: v1
kind: Secret
metadata:
name: myapi-secrets
type: Opaque
data:
connectionstring: U2VydmVyPW15c3FsO0RhdGFiYXNlPW15ZGI7VXNlcj1yb290O1Bhc3N3b3JkPXBhc3M=
6. Ingress - HTTP/HTTPS routing
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapi-ingress
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
tls:
- hosts:
- api.mydomain.com
secretName: myapi-tls
rules:
- host: api.mydomain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: myapi-service
port:
number: 80
Common kubectl Commands:
# Deploy application
kubectl apply -f deployment.yaml
# Get resources
kubectl get pods
kubectl get deployments
kubectl get services
# Scale deployment
kubectl scale deployment myapi-deployment --replicas=5
# View logs
kubectl logs myapi-pod
# Execute command in pod
kubectl exec -it myapi-pod -- /bin/bash
# Update deployment (rolling update)
kubectl set image deployment/myapi-deployment myapi=myapi:v2
# Rollback deployment
kubectl rollout undo deployment/myapi-deployment
# Delete resources
kubectl delete -f deployment.yaml
When to Use Kubernetes:
✅ Use K8s when:
- Running microservices architecture
- Need high availability and auto-scaling
- Managing multiple environments (dev, staging, prod)
- Need container orchestration at scale
❌ Avoid K8s when:
- Simple monolithic application
- Small team with limited DevOps expertise
- Low traffic applications
- Development/testing only