DevLearn

Kubernetes Deployments & Scaling

Deployment strategies, rolling updates, HPA, VPA, and replica management

Deploy and scale applications: Deployment rollout strategies, horizontal pod autoscaler (HPA), vertical pod autoscaler (VPA), ConfigMaps/Secrets updates, and rollback procedures.

# Deployment
kubectl create deployment nginx --image=nginx --replicas=3

# Rolling update
kubectl set image deployment/nginx nginx=nginx:1.19

# Scale
kubectl scale deployment nginx --replicas=5

# HPA
kubectl autoscale deployment nginx --min=2 --max=10 --cpu-percent=80

# Rollout status
kubectl rollout status deployment/nginx

# Rollback
kubectl rollout undo deployment/nginx
kubectl rollout undo deployment/nginx --to-revision=2

# HPA YAML
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: nginx-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 80