Files
mixingx.hub.chart/release-charts/mixingx-agent-unit/templates/unit.yaml
T
薛佳帆 407aef89e1 fix(postgres): 全部 postgres StatefulSet 三件套修复——绕过镜像内 gosu 直跑 + 特权容器
根因:官方 postgres:17 镜像(2026-08 构建)内 gosu 在新内核(Ubuntu 26.04 kernel 7.0.0-39+)上
用户态死循环,容器假活(Running 但 5432 无服务、PGDATA 空、零日志);绕过 gosu 后 PG17 恢复期
signal checkpoint 再遇权限死循环,故三件缺一不可:
- pod securityContext: runAsUser/runAsGroup/fsGroup=999(以 postgres 用户直跑,跳过 gosu)
- container command: docker-entrypoint.sh postgres(非 root 下 entrypoint 自动跳过 gosu)
- container securityContext: privileged(否则恢复期 'could not signal for checkpoint: Permission denied')

涉及 5 个模板:sso/ultra/audit(audit-db)/platform(audit)/agent-unit 各自内嵌的 postgres。
实测:xjf1641(Xeon+kernel43)与 wytest(i5+kernel42)原始定义必死、打补丁后稳定运行;
kernel 7.0.0-38 老机(如 184)暂未触发但同机制不免疫,升级内核前必须先吃本修复。
2026-11-10 16:19:50 +08:00

304 lines
11 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{- $name := include "mixingx-unit.name" . -}}
{{- $webName := include "mixingx-unit.webName" . -}}
{{- $database := include "mixingx-unit.database" . -}}
{{- $serviceId := include "mixingx-unit.serviceId" . -}}
{{- $basePath := include "mixingx-unit.basePath" . -}}
{{- $pgHost := printf "%s-postgres-service" $name -}}
{{- $pgCredentialsSecretName := include "mixingx-unit.postgresCredentialsSecretName" . -}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $name }}-deployment
labels:
app.kubernetes.io/name: mixingx
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: {{ $name }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/component: {{ $name }}
template:
metadata:
labels:
app.kubernetes.io/component: {{ $name }}
annotations:
checksum/config: {{ include "mixingx-unit.backendConfigData" . | sha256sum }}
checksum/postgres-role-sql: {{ .Files.Get "files/provision-agent-role.sql" | sha256sum }}
spec:
{{ include "mixingx-unit.backendScheduling" . | nindent 6 }}
initContainers:
- name: provision-postgres-role
image: {{ .Values.images.postgres.repository }}:{{ .Values.images.postgres.tag | default "latest" }}
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "-ec"]
args:
- |
attempt=0
until pg_isready --host="$POSTGRESQL_HOST" --port="$POSTGRESQL_PORT" --username="$POSTGRES_ADMIN_USERNAME" --dbname="$POSTGRESQL_DATABASENAME"; do
attempt=$((attempt + 1))
if [ "$attempt" -ge 60 ]; then
echo "PostgreSQL did not become ready within 120 seconds" >&2
exit 1
fi
sleep 2
done
exec psql \
--host="$POSTGRESQL_HOST" \
--port="$POSTGRESQL_PORT" \
--username="$POSTGRES_ADMIN_USERNAME" \
--dbname="$POSTGRESQL_DATABASENAME" \
--file=/opt/mixingx/postgres/provision-agent-role.sql
env:
- name: POSTGRESQL_HOST
value: "{{ $pgHost }}"
- name: POSTGRESQL_PORT
value: "{{ .Values.sharedInfra.postgres.port }}"
- name: POSTGRESQL_DATABASENAME
value: "{{ $database }}"
- name: POSTGRES_ADMIN_USERNAME
value: "{{ .Values.sharedInfra.postgres.adminUsername }}"
- name: AGENT_DB_USERNAME
value: "{{ .Values.sharedInfra.postgres.appUsername }}"
- name: IDLE_IN_TRANSACTION_SESSION_TIMEOUT
value: "{{ .Values.sharedInfra.postgres.idleInTransactionSessionTimeout }}"
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: {{ $pgCredentialsSecretName }}
key: {{ .Values.sharedInfra.postgres.credentialsSecret.adminPasswordKey }}
- name: AGENT_DB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ $pgCredentialsSecretName }}
key: {{ .Values.sharedInfra.postgres.credentialsSecret.appPasswordKey }}
volumeMounts:
- name: postgres-role-provisioning
mountPath: /opt/mixingx/postgres
readOnly: true
containers:
- name: {{ $name }}
image: {{ include "mixingx-agent-unit.image" (dict "registry" .Values.global.imageRegistry "image" .Values.images.agent) | quote }}
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: {{ .Values.ports.backend }}
protocol: TCP
envFrom:
- configMapRef:
name: {{ $name }}-config
- secretRef:
name: {{ $name }}-secrets
env:
- name: TZ
value: "{{ .Values.timezone | default "Asia/Shanghai" }}"
- name: ConnectionStrings__PostgreSQL
valueFrom:
secretKeyRef:
name: {{ $pgCredentialsSecretName }}
key: {{ .Values.sharedInfra.postgres.credentialsSecret.connectionStringKey }}
- name: POSTGRESQL_PASSWORD
valueFrom:
secretKeyRef:
name: {{ $pgCredentialsSecretName }}
key: {{ .Values.sharedInfra.postgres.credentialsSecret.appPasswordKey }}
livenessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 120
periodSeconds: 30
timeoutSeconds: 15
failureThreshold: 12
readinessProbe:
httpGet:
path: /alive
port: http
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 10
failureThreshold: 8
volumes:
- name: postgres-role-provisioning
configMap:
name: {{ $name }}-postgres-role-provisioning
---
apiVersion: v1
kind: Service
metadata:
name: {{ $name }}-service
labels:
app.kubernetes.io/name: mixingx
app.kubernetes.io/component: {{ $name }}
mixingx.io/role: {{ .Values.role }}
mixingx.io/node-id: {{ $name }}
annotations:
mixingx.io/description: {{ .Values.description | quote }}
spec:
selector:
app.kubernetes.io/component: {{ $name }}
ports:
- name: http
port: {{ .Values.ports.backend }}
targetPort: http
protocol: TCP
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $name }}-config
data:
{{- include "mixingx-unit.backendConfigData" . | nindent 2 }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ $name }}-secrets
type: Opaque
stringData:
ConnectionStrings__redis: "{{ .Values.sharedInfra.redis.host }}:{{ .Values.sharedInfra.redis.port }},password={{ .Values.sharedInfra.redis.password }}"
REDIS_PASSWORD: "{{ .Values.sharedInfra.redis.password }}"
REDIS_URI: "redis://:{{ .Values.sharedInfra.redis.password }}@{{ .Values.sharedInfra.redis.host }}:{{ .Values.sharedInfra.redis.port }}"
ConnectionStrings__messaging: "amqp://{{ .Values.sharedInfra.rabbitmq.username }}:{{ .Values.sharedInfra.rabbitmq.password }}@{{ .Values.sharedInfra.rabbitmq.host }}:{{ .Values.sharedInfra.rabbitmq.port }}"
MESSAGING_PASSWORD: "{{ .Values.sharedInfra.rabbitmq.password }}"
MESSAGING_URI: "amqp://{{ .Values.sharedInfra.rabbitmq.username }}:{{ .Values.sharedInfra.rabbitmq.password }}@{{ .Values.sharedInfra.rabbitmq.host }}:{{ .Values.sharedInfra.rabbitmq.port }}"
{{- range .Values.mqttCredentials }}
AgentEdgeMqtt__Credentials__{{ .credentialRef }}__UserName: "{{ .username }}"
AgentEdgeMqtt__Credentials__{{ .credentialRef }}__Password: "{{ .password }}"
{{- end }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $webName }}-deployment
labels:
app.kubernetes.io/name: mixingx
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: {{ $webName }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/component: {{ $webName }}
template:
metadata:
labels:
app.kubernetes.io/component: {{ $webName }}
spec:
{{ include "mixingx-unit.followerScheduling" . | nindent 6 }}
containers:
- name: {{ $webName }}
image: {{ include "mixingx-agent-unit.image" (dict "registry" .Values.global.imageRegistry "image" .Values.images.agentWeb) | quote }}
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: {{ .Values.ports.frontend }}
protocol: TCP
env:
- name: TZ
value: "{{ .Values.timezone | default "Asia/Shanghai" }}"
- name: VITE_BASE_PATH
value: "{{ $basePath }}"
- name: PORT
value: "{{ .Values.ports.frontend }}"
---
apiVersion: v1
kind: Service
metadata:
name: {{ $webName }}-service
labels:
app.kubernetes.io/name: mixingx
app.kubernetes.io/component: {{ $webName }}
mixingx.io/role: web
mixingx.io/node-id: {{ $webName }}
spec:
selector:
app.kubernetes.io/component: {{ $webName }}
ports:
- name: http
port: {{ .Values.ports.frontend }}
targetPort: http
protocol: TCP
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ $name }}-postgres
labels:
app.kubernetes.io/name: mixingx
app.kubernetes.io/component: {{ $name }}-postgres
spec:
serviceName: {{ $name }}-postgres-service
replicas: 1
selector:
matchLabels:
app.kubernetes.io/component: {{ $name }}-postgres
volumeClaimTemplates:
- metadata:
name: data
{{- if .Values.storage.keep }}
annotations:
helm.sh/resource-policy: keep
{{- end }}
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: {{ include "mixingx-unit.storageClassName" . }}
resources:
requests:
storage: {{ .Values.storage.size }}
template:
metadata:
labels:
app.kubernetes.io/component: {{ $name }}-postgres
spec:
{{ include "mixingx-unit.followerScheduling" . | nindent 6 }}
# postgres 以专用用户直跑,绕过镜像内 gosu(新内核下 gosu 用户态死循环,
# 见 ADR/工单:kernel 7.0.0-39+ × gosu 兼容 bug;三件套缺一不可)
securityContext:
runAsUser: 999
runAsGroup: 999
fsGroup: 999
containers:
- name: postgres
command: ["docker-entrypoint.sh", "postgres"]
securityContext:
privileged: true
image: {{ include "mixingx-agent-unit.image" (dict "registry" .Values.global.imageRegistry "image" .Values.images.postgres) | quote }}
imagePullPolicy: IfNotPresent
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ $pgCredentialsSecretName }}
key: {{ .Values.sharedInfra.postgres.credentialsSecret.adminPasswordKey }}
- name: POSTGRES_DB
value: "{{ $database }}"
- name: POSTGRES_USER
value: "{{ .Values.sharedInfra.postgres.adminUsername }}"
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
ports:
- name: tcp
containerPort: {{ .Values.ports.postgres }}
protocol: TCP
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
---
apiVersion: v1
kind: Service
metadata:
name: {{ $name }}-postgres-service
labels:
app.kubernetes.io/name: mixingx
app.kubernetes.io/component: {{ $name }}-postgres
spec:
selector:
app.kubernetes.io/component: {{ $name }}-postgres
ports:
- name: tcp
port: {{ .Values.ports.postgres }}
targetPort: tcp
protocol: TCP