Kubernetes (K8s) orchestrates containers at scale. It sounds intimidating, but deploying your first app is surprisingly straightforward.
Core Concepts in 60 Seconds
- Pod: Smallest unit — one or more containers running together
- Deployment: Manages pods — handles scaling, updates, rollbacks
- Service: Stable network endpoint for accessing pods
- Namespace: Virtual cluster for organizing resources
Setup: Local K8s with minikube
# Install minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
# Start cluster
minikube start
# Verify
kubectl get nodes
Deploy Your First App
Step 1: Create a Deployment
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
labels:
app: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myuser/myapp:v1
ports:
- containerPort: 8000
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "500m"
readinessProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 15
periodSeconds: 20
kubectl apply -f deployment.yaml
kubectl get pods # watch them come up
Step 2: Expose with a Service
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 8000
type: LoadBalancer
kubectl apply -f service.yaml
minikube service myapp-service # opens in browser
Step 3: ConfigMaps and Secrets
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: myapp-config
data:
LOG_LEVEL: "info"
MAX_CONNECTIONS: "100"
---
# secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: myapp-secrets
type: Opaque
stringData:
DATABASE_URL: "postgresql://user:pass@db:5432/mydb"
API_KEY: "sk-secret-key-here"
Use them in your deployment:
spec:
containers:
- name: myapp
envFrom:
- configMapRef:
name: myapp-config
- secretRef:
name: myapp-secrets
Scaling
# Manual scaling
kubectl scale deployment myapp --replicas=5
# Auto-scaling
kubectl autoscale deployment myapp --min=2 --max=10 --cpu-percent=70
Rolling Updates
# Update image
kubectl set image deployment/myapp myapp=myuser/myapp:v2
# Watch rollout
kubectl rollout status deployment/myapp
# Rollback if something goes wrong
kubectl rollout undo deployment/myapp
Essential kubectl Commands
kubectl get pods # list pods
kubectl get pods -w # watch pods in real-time
kubectl describe pod <name> # detailed pod info
kubectl logs <pod-name> # view logs
kubectl logs <pod-name> -f # stream logs
kubectl exec -it <pod-name> -- bash # shell into pod
kubectl top pods # resource usage
kubectl get events --sort-by='.lastTimestamp' # recent events
Key Takeaways
- Start with minikube for local development
- Deployment + Service is the minimum viable K8s setup
- Always set resource requests and limits
- Use readiness and liveness probes for reliability
- ConfigMaps for config, Secrets for sensitive data
6. Rolling updates give you zero-downtime deployments
🚀 Level up your AI workflow! Check out my AI Developer Mega Prompt Pack — 80 battle-tested prompts for developers. $9.99
Top comments (0)