Kubernetes
Container orchestration with Kubernetes — pods, services, deployments, autoscaling and health checks.
What is Kubernetes?
Kubernetes (K8s) is a container orchestration platform that automates the deployment, scaling and management of containerized applications. It was created by Google and is today the de facto standard for running workloads in production.
Kubernetes solves problems that Docker alone cannot handle at scale:
- How do I distribute my containers across multiple machines?
- How do I scale automatically when there’s more traffic?
- What happens if a container fails — who restarts it?
- How do I perform rolling updates without downtime?
Core concepts
Pod
A Pod is the smallest deployable unit in Kubernetes. It contains one or more containers that share network and storage. In practice, most pods have a single container.
apiVersion: v1
kind: Pod
metadata:
name: my-app
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:1.0.0
ports:
- containerPort: 3000
Service
A Service exposes a set of pods as a stable network service. Pods are ephemeral (they can die and be recreated), but the Service keeps a fixed IP and DNS.
Service types:
- ClusterIP (default): accessible only within the cluster
- NodePort: exposes the service on a port of each node
- LoadBalancer: creates an external load balancer (on cloud providers)
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app
ports:
- port: 80
targetPort: 3000
type: ClusterIP
Deployment
A Deployment manages the lifecycle of pods: how many replicas to run, how to update them and how to roll back if something fails.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:1.0.0
ports:
- containerPort: 3000
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
Health checks
Kubernetes uses probes to check the state of containers:
Liveness probe
Checks whether the container is alive. If it fails, Kubernetes restarts the container.
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 10
periodSeconds: 15
failureThreshold: 3
Readiness probe
Checks whether the container is ready to receive traffic. If it fails, Kubernetes stops sending it requests (but does not restart it).
readinessProbe:
httpGet:
path: /ready
port: 3000
initialDelaySeconds: 5
periodSeconds: 10
Startup probe
For applications that are slow to start. Until the startup probe passes, the other probes are not executed.
startupProbe:
httpGet:
path: /health
port: 3000
failureThreshold: 30
periodSeconds: 5
Scaling
Manual scaling
kubectl scale deployment my-app --replicas=5
Horizontal Pod Autoscaler (HPA)
Automatically scales the number of pods based on metrics such as CPU or memory:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
ConfigMaps and Secrets
ConfigMap
For non-sensitive configuration:
apiVersion: v1
kind: ConfigMap
metadata:
name: my-app-config
data:
LOG_LEVEL: "info"
API_TIMEOUT: "30s"
Secret
For sensitive data (base64-encoded):
apiVersion: v1
kind: Secret
metadata:
name: my-app-secrets
type: Opaque
data:
DATABASE_PASSWORD: cGFzc3dvcmQxMjM=
Namespaces
Namespaces let you divide a cluster into isolated logical environments:
kubectl create namespace staging
kubectl create namespace production
Each namespace can have its own resources, limits and access policies.
Summary
Kubernetes is the standard platform for orchestrating containers in production. Its key abstractions — Pods, Services, Deployments — together with health checks, autoscaling and configuration management, provide everything needed to run distributed applications reliably and at scale.