YouTip LogoYouTip

Kubernetes Scaling and Updates

Introduction

Kubernetes provides built-in scaling and update mechanisms. Horizontal Pod Autoscaler adjusts replicas based on load, and rolling updates ensure zero-downtime deployments.

Manual Scaling

# Scale deployment
kubectl scale deployment myapp --replicas=5

# Check replica count
kubectl get deployment myapp

Horizontal Pod Autoscaler

# Prerequisites: metrics-server
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

# Create autoscaler
kubectl autoscale deployment myapp 
  --min=2 --max=10 --cpu-percent=70

# Check HPA status
kubectl get hpa

Rolling Updates

# Update strategy in deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    spec:
      containers:
      - name: myapp
        image: myapp:2.0

Rollout Management

# Check rollout status
kubectl rollout status deployment/myapp

# View rollout history
kubectl rollout history deployment/myapp

# Rollback to previous version
kubectl rollout undo deployment/myapp

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

Summary

Scale manually with kubectl scale or automatically with HPA. Use rolling updates for zero-downtime deployments and kubectl rollout for version management.

← Linux Shell Basic OperatorsKubernetes ConfigMaps and Secr β†’