Operations

Kubernetes Autoscaling


HorizontalPodAutoscaler

Scales between 3 and 10 replicas based on CPU (70%) and memory (80%) utilization:

1
apiVersion: autoscaling/v2
2
kind: HorizontalPodAutoscaler
3
metadata:
4
name: orchestrator
5
namespace: orcher
6
spec:
7
scaleTargetRef:
8
apiVersion: apps/v1
9
kind: Deployment
10
name: orchestrator
11
minReplicas: 3
12
maxReplicas: 10
13
metrics:
14
- type: Resource
15
resource:
16
name: cpu
17
target:
18
type: Utilization
19
averageUtilization: 70
20
- type: Resource
21
resource:
22
name: memory
23
target:
24
type: Utilization
25
averageUtilization: 80
26
behavior:
27
scaleDown:
28
stabilizationWindowSeconds: 300
29
policies:
30
- type: Percent
31
value: 50
32
periodSeconds: 60
33
selectPolicy: Min
34
scaleUp:
35
stabilizationWindowSeconds: 60
36
policies:
37
- type: Percent
38
value: 100
39
periodSeconds: 30
40
- type: Pods
41
value: 2
42
periodSeconds: 30
43
selectPolicy: Max

Scale-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):

1
apiVersion: policy/v1
2
kind: PodDisruptionBudget
3
metadata:
4
name: orchestrator
5
namespace: orcher
6
spec:
7
minAvailable: 2
8
selector:
9
matchLabels:
10
app: orchestrator
11
unhealthyPodEvictionPolicy: AlwaysAllow

Kustomize

The kustomization.yaml ties all resources together and provides override points:

1
apiVersion: kustomize.config.k8s.io/v1beta1
2
kind: Kustomization
3
4
namespace: orcher
5
6
commonLabels:
7
app.kubernetes.io/name: orchestrator
8
app.kubernetes.io/component: coordination
9
app.kubernetes.io/part-of: orcher
10
11
resources:
12
- configmap.yaml
13
- deployment.yaml
14
- service.yaml
15
- rbac.yaml
16
- hpa.yaml
17
- pdb.yaml
18
19
images:
20
- name: orcher/orchestrator
21
newTag: latest
22
23
replicas:
24
- name: orchestrator
25
count: 3

Override the image tag for a specific release:

1
cd services/orchestrator/k8s
2
kustomize edit set image orcher/orchestrator=your-registry/orcher/orchestrator:v1.0.0
3
kubectl apply -k .

Next Steps