Kubernetes 101: Understanding Pods, Services, and Deployments
Kubernetes (K8s) is the industry standard for container orchestration. It automates deploying, scaling, and managing containerized applications across clusters of machines.
Core Concepts
Pods
A Pod is the smallest deployable unit in Kubernetes. It wraps one or more containers that share networking and storage.
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25-alpine
ports:
- containerPort: 80
Deployments
A Deployment manages a set of identical Pods and handles rolling updates and rollbacks.
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:1.25-alpine
ports:
- containerPort: 80
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "250m"
memory: "256Mi"
Services
A Service provides stable networking for a set of Pods. Types include:
- ClusterIP (default) — internal cluster access only
- NodePort — exposes on each node's IP at a static port
- LoadBalancer — provisions an external load balancer (cloud)
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- port: 80
targetPort: 80
Key kubectl Commands
# Apply a manifest
kubectl apply -f deployment.yaml
# Get resources
kubectl get pods
kubectl get deployments
kubectl get services
# Describe a resource for details
kubectl describe pod nginx-pod
# View logs
kubectl logs -f deployment/nginx-deployment
# Scale a deployment
kubectl scale deployment nginx-deployment --replicas=5
# Delete resources
kubectl delete -f deployment.yaml
Namespaces
Namespaces isolate resources within a cluster. Use them to separate environments:
kubectl create namespace staging
kubectl apply -f deployment.yaml -n staging
kubectl get pods -n staging
ConfigMaps and Secrets
Store configuration outside your containers:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
DATABASE_HOST: "postgres.default.svc.cluster.local"
LOG_LEVEL: "info"
Health Checks
Always define liveness and readiness probes:
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 15
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
Next Steps
Once comfortable with these primitives, explore Ingress controllers for HTTP routing, Helm for packaging, and Horizontal Pod Autoscaler for dynamic scaling.
Tagged with
Enjoyed this article?
Get more DevOps insights delivered to your inbox.
Get new posts by email
Subscribe to get an email when a new blog post is published. Skip anytime.
No spam, unsubscribe anytime.
Discussion
0 comments
Sign in to join the conversation.
Be the first to comment
Start a conversation about this post
