Skip to content
Clone

feat(chart): let im scale out and be drained safely

im had no autoscaling or PodDisruptionBudget support at all, unlike
apihost. Both are added with the same shape, including the fix that keeps
`replicas` rendered (as minReplicas) when the HPA is enabled - omitting it
lets helm's three-way merge null the field and the API server defaults it
back to 1, which for this Deployment would mean every upgrade dropping the
WS gateway to a single pod mid-session.
ZhenYi committed
parent 381e636 commit 7bb44f6 Browse files

2 files changed

+71 −0

File tree 2
Modified chart/templates/im.yaml View chart/templates/im.yaml
@@ -7,7 +7,13 @@
77 {{- include "gitdata.labels" . | nindent 4 }}
88 app.kubernetes.io/component: im
99spec:
10 {{- if .Values.im.autoscaling.enabled }}
11 # 见 apihost.yaml 同名注释:省略 replicas 会被 three-way merge patch 成 null,
12 # API server 按默认值收成 1,升级瞬间 WS 只剩一个网关。
13 replicas: {{ .Values.im.autoscaling.minReplicas }}
14 {{- else }}
1015 replicas: {{ .Values.im.replicaCount }}
16 {{- end }}
1117 revisionHistoryLimit: 3
1218 strategy:
1319 type: RollingUpdate
@@ -100,3 +106,55 @@
100106 port: {{ .Values.im.port }}
101107 targetPort: http
102108{{- end }}
109{{- if .Values.im.autoscaling.enabled }}
110---
111apiVersion: autoscaling/v2
112kind: HorizontalPodAutoscaler
113metadata:
114 name: {{ printf "%s-im" (include "gitdata.fullname" .) }}
115 labels:
116 {{- include "gitdata.labels" . | nindent 4 }}
117 app.kubernetes.io/component: im
118spec:
119 scaleTargetRef:
120 apiVersion: apps/v1
121 kind: Deployment
122 name: {{ printf "%s-im" (include "gitdata.fullname" .) }}
123 minReplicas: {{ .Values.im.autoscaling.minReplicas }}
124 maxReplicas: {{ .Values.im.autoscaling.maxReplicas }}
125 metrics:
126 - type: Resource
127 resource:
128 name: cpu
129 target:
130 type: Utilization
131 averageUtilization: {{ .Values.im.autoscaling.targetCPUUtilizationPercentage }}
132 {{- if gt (int (.Values.im.autoscaling.targetMemoryUtilizationPercentage | default 0)) 0 }}
133 - type: Resource
134 resource:
135 name: memory
136 target:
137 type: Utilization
138 averageUtilization: {{ .Values.im.autoscaling.targetMemoryUtilizationPercentage }}
139 {{- end }}
140 {{- with .Values.im.autoscaling.behavior }}
141 behavior:
142 {{- toYaml . | nindent 4 }}
143 {{- end }}
144{{- end }}
145{{- if .Values.im.pdb.enabled }}
146---
147apiVersion: policy/v1
148kind: PodDisruptionBudget
149metadata:
150 name: {{ printf "%s-im" (include "gitdata.fullname" .) }}
151 labels:
152 {{- include "gitdata.labels" . | nindent 4 }}
153 app.kubernetes.io/component: im
154spec:
155 minAvailable: {{ .Values.im.pdb.minAvailable }}
156 selector:
157 matchLabels:
158 {{- include "gitdata.selectorLabels" . | nindent 6 }}
159 app.kubernetes.io/component: im
160{{- end }}
Modified chart/values.yaml View chart/values.yaml
@@ -198,10 +198,23 @@
198198 resources:
199199 requests: { cpu: 100m, memory: 128Mi }
200200 limits: { memory: 512Mi }
201 autoscaling:
202 enabled: false
203 minReplicas: 2
204 maxReplicas: 6
205 targetCPUUtilizationPercentage: 70
206 # 0 disables the memory metric. Against the 128Mi request this is the
207 # connection-count guard: each live socket costs buffers plus its own
208 # pubsub pump, and the limit (512Mi) is far above where a pod should be.
209 targetMemoryUtilizationPercentage: 0
210 behavior: {}
201211 maxSurge: 1
202212 maxUnavailable: 0
203213 podAntiAffinity: soft # soft | hard | ""
204214 extraEnv: []
215 pdb:
216 enabled: true
217 minAvailable: 1
205218
206219# ---------------------------------------------------------------------------
207220# AI:评审 / 仓库总结 / release 文案。启用前必须提供 OpenAI 兼容端点。