Kubernetes Autoscaling
HorizontalPodAutoscaler
Scales between 3 and 10 replicas based on CPU (70%) and memory (80%) utilization:
1apiVersion: autoscaling/v22kind: HorizontalPodAutoscaler3metadata:4 name: orchestrator5 namespace: orcher6spec:7 scaleTargetRef:8 apiVersion: apps/v19 kind: Deployment10 name: orchestrator11 minReplicas: 312 maxReplicas: 1013 metrics:14 - type: Resource15 resource:16 name: cpu17 target:18 type: Utilization19 averageUtilization: 7020 - type: Resource21 resource:22 name: memory23 target:24 type: Utilization25 averageUtilization: 8026 behavior:27 scaleDown:28 stabilizationWindowSeconds: 30029 policies:30 - type: Percent31 value: 5032 periodSeconds: 6033 selectPolicy: Min34 scaleUp:35 stabilizationWindowSeconds: 6036 policies:37 - type: Percent38 value: 10039 periodSeconds: 3040 - type: Pods41 value: 242 periodSeconds: 3043 selectPolicy: MaxScale-down is conservative (5-minute stabilization, removes at most 50% per minute) to prevent flapping. Scale-up is aggressive (1-minute stabilization, up to 2 pods per 30 seconds) to handle traffic spikes.
PodDisruptionBudget
Ensures at least 2 pods remain available during voluntary disruptions (node drain, rolling updates):
1apiVersion: policy/v12kind: PodDisruptionBudget3metadata:4 name: orchestrator5 namespace: orcher6spec:7 minAvailable: 28 selector:9 matchLabels:10 app: orchestrator11 unhealthyPodEvictionPolicy: AlwaysAllowKustomize
The kustomization.yaml ties all resources together and provides override points:
1apiVersion: kustomize.config.k8s.io/v1beta12kind: Kustomization34namespace: orcher56commonLabels:7 app.kubernetes.io/name: orchestrator8 app.kubernetes.io/component: coordination9 app.kubernetes.io/part-of: orcher1011resources:12 - configmap.yaml13 - deployment.yaml14 - service.yaml15 - rbac.yaml16 - hpa.yaml17 - pdb.yaml1819images:20 - name: orcher/orchestrator21 newTag: latest2223replicas:24 - name: orchestrator25 count: 3Override the image tag for a specific release:
1cd services/orchestrator/k8s2kustomize edit set image orcher/orchestrator=your-registry/orcher/orchestrator:v1.0.03kubectl apply -k .Next Steps
- Production — Monitoring, scaling, security, and troubleshooting
- Manifests — Deployment, Service, ConfigMap, and RBAC manifests
- Kubernetes Overview — Prerequisites and quick start