Skip to content
Clone

feat(chart): make the apihost HPA usable (memory target, behavior, no scale-to-1)

Three gaps in the existing autoscaling scaffolding:

- targetMemoryUtilizationPercentage (0 = off) so the memory metric can be
  declared at all. It is the metric that matters here: apihost limits 1Gi
  against a 256Mi request, and the oxocache L1 grows inside the process,
  so CPU alone would let a pod reach its limit and be OOM-killed before
  HPA ever reacted.
- behavior passthrough, so a release can tune stabilization windows and
  per-period policies instead of living with the cluster default.
- the Deployment now renders replicas = minReplicas when autoscaling is on
  instead of omitting the field. Omitting it is a trap: helm's three-way
  merge turns the absent field into a null patch, the API server re-applies
  its default of 1, and every upgrade briefly drops the main API to a
  single replica before the HPA notices.
ZhenYi committed
parent 20a153a commit 7b1d475 Browse files

2 files changed

+24 −1

File tree 2
Modified chart/templates/apihost.yaml View chart/templates/apihost.yaml
@@ -7,7 +7,13 @@
77 {{- include "gitdata.labels" . | nindent 4 }}
88 app.kubernetes.io/component: apihost
99spec:
10 {{- if not .Values.apihost.autoscaling.enabled }}
10 {{- if .Values.apihost.autoscaling.enabled }}
11 # 开着 HPA 时也要写 replicas,且写 minReplicas:省略该字段会让 helm 的
12 # three-way merge 把它 patch 成 null,API server 随即按默认值收成 1,
13 # 升级瞬间主 API 少一个副本。写 minReplicas 则升级前后副本数不变,
14 # 之后完全由 HPA 接管(超出 min 的扩容不会被这张清单拉回)。
15 replicas: {{ .Values.apihost.autoscaling.minReplicas }}
16 {{- else }}
1117 replicas: {{ .Values.apihost.replicaCount }}
1218 {{- end }}
1319 revisionHistoryLimit: 3
@@ -138,6 +144,18 @@
138144 target:
139145 type: Utilization
140146 averageUtilization: {{ .Values.apihost.autoscaling.targetCPUUtilizationPercentage }}
147 {{- if gt (int (.Values.apihost.autoscaling.targetMemoryUtilizationPercentage | default 0)) 0 }}
148 - type: Resource
149 resource:
150 name: memory
151 target:
152 type: Utilization
153 averageUtilization: {{ .Values.apihost.autoscaling.targetMemoryUtilizationPercentage }}
154 {{- end }}
155 {{- with .Values.apihost.autoscaling.behavior }}
156 behavior:
157 {{- toYaml . | nindent 4 }}
158 {{- end }}
141159{{- end }}
142160{{- if .Values.apihost.pdb.enabled }}
143161---
Modified chart/values.yaml View chart/values.yaml
@@ -109,6 +109,11 @@
109109 minReplicas: 2
110110 maxReplicas: 8
111111 targetCPUUtilizationPercentage: 70
112 # 0 disables the memory metric. The limit is 1Gi while the request is 256Mi,
113 # so a memory target is what actually keeps the L1 cache from being OOM-killed.
114 targetMemoryUtilizationPercentage: 0
115 # Empty map renders no `behavior:` block (k8s default scaling policy).
116 behavior: {}
112117 maxSurge: 1
113118 maxUnavailable: 0
114119 podAntiAffinity: soft # soft | hard | ""