Kubernetes for Beginners
Pods, deployments, services, and the kubectl commands you will actually use.
What is Kubernetes?
Kubernetes (K8s) manages your containers in production. Docker runs a single container. Kubernetes runs hundreds or thousands of them across multiple machines, handles load balancing, restarts crashed containers, rolls out updates without downtime, and scales up or down based on traffic.
Think of Docker as a shipping container and Kubernetes as the port that manages where every container goes, makes sure they're healthy, and routes ships (traffic) to the right ones.
Pods - The Smallest Unit
A Pod is the smallest deployable unit in Kubernetes. It wraps one or more containers that share storage and network. In practice, most pods contain a single container. You rarely create pods directly - you use Deployments instead - but understanding pods is essential.
apiVersion: v1
kind: Pod
metadata:
name: my-app
labels:
app: my-app
spec:
containers:
- name: my-app
image: myapp:latest
ports:
- containerPort: 3000
resources:
requests:
memory: '128Mi'
cpu: '250m'
limits:
memory: '256Mi'
cpu: '500m'Deployments - Managing Replicas
A Deployment tells Kubernetes: "I want 3 copies of this pod running at all times." If one crashes, Kubernetes automatically creates a replacement. When you push a new image, it performs a rolling update - replacing pods one at a time so there is zero downtime.
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: myapp:latest
ports:
- containerPort: 3000Services - Networking
Pods get random IP addresses that change when they restart. A Service gives your pods a stable address and load-balances traffic across all healthy replicas. The LoadBalancer type exposes your service to the internet.
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
type: LoadBalancer
selector:
app: my-app
ports:
- port: 80
targetPort: 3000kubectl - Your Command Line Tool
kubectl is how you talk to your Kubernetes cluster. These are the commands you will use every single day.
# Apply a configuration file
kubectl apply -f deployment.yaml
# List all pods
kubectl get pods
# Get detailed info about a pod
kubectl describe pod my-app-xyz123
# View pod logs
kubectl logs my-app-xyz123
# Scale a deployment
kubectl scale deployment my-app --replicas=5
# Delete a resource
kubectl delete deployment my-app
# Port forward for local testing
kubectl port-forward svc/my-app-service 8080:80Key Takeaways
- - Pods are the smallest unit, but you rarely create them directly
- - Deployments manage replicas, self-healing, and rolling updates
- - Services provide stable networking and load balancing
- - kubectl apply, get, describe, and logs are your daily drivers
- - Start with a managed service like EKS, GKE, or AKS before running your own cluster