feat(audit): 审计服务重构为PostgreSQL + MQTT架构并添加前端
- 将数据库从MongoDB迁移至PostgreSQL,更新连接配置和环境变量 - 引入MQTT协议支持,配置NanoMQ作为消息代理并添加管理API - 添加审计服务前端部署,使用nginx托管Web界面 - 配置JWT鉴权和SSO集成,添加健康检查探针 - 更新共享基础设施模板以支持audit-nanomq服务 - 调整端口号从5600至5900,增加并发消费队列配置
This commit is contained in:
1 parent
8ffbf97cce
commit
114321a888
5 files changed
+307
-33
No files matched your search
@@ -8,20 +8,15 @@ metadata:
|
||||
labels:
|
||||
app.kubernetes.io/name: mixingx
|
||||
app.kubernetes.io/component: audit
|
||||
mixingx.io/role: audit
|
||||
mixingx.io/node-id: audit
|
||||
spec:
|
||||
replicas: {{ .Values.audit.replicas | default 1 }}
|
||||
replicas: {{ .Values.audit.replicas | default 2 }}
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/component: audit
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/name: mixingx
|
||||
app.kubernetes.io/component: audit
|
||||
mixingx.io/role: audit
|
||||
mixingx.io/node-id: audit
|
||||
spec:
|
||||
{{ include "mixingx-audit.tierAffinity" (dict "role" "audit" "root" $root) | nindent 6 }}
|
||||
containers:
|
||||
@@ -35,20 +30,64 @@ spec:
|
||||
env:
|
||||
- name: TZ
|
||||
value: "{{ $root.Values.timezone | default "Asia/Shanghai" }}"
|
||||
- name: MONGODB_URI
|
||||
value: "mongodb://{{ .Values.sharedInfra.mongo.username }}:{{ .Values.sharedInfra.mongo.password }}@{{ .Values.sharedInfra.mongo.host }}:{{ .Values.sharedInfra.mongo.port }}"
|
||||
- name: MONGODB_DATABASE
|
||||
value: "{{ .Values.sharedInfra.mongo.database }}"
|
||||
- name: RABBITMQ_URI
|
||||
value: "amqp://{{ .Values.sharedInfra.rabbitmq.username }}:{{ .Values.sharedInfra.rabbitmq.password }}@{{ .Values.sharedInfra.rabbitmq.host }}:{{ .Values.sharedInfra.rabbitmq.port }}"
|
||||
- name: PORT
|
||||
value: "{{ .Values.audit.port }}"
|
||||
- name: HOST
|
||||
value: "0.0.0.0"
|
||||
# PostgreSQL
|
||||
- name: AUDIT_PG_URI
|
||||
value: "postgresql://{{ $root.Values.sharedInfra.postgres.username }}:{{ $root.Values.sharedInfra.postgres.password }}@{{ .Values.audit.database }}-postgres-service:{{ $root.Values.sharedInfra.postgres.port }}/{{ .Values.audit.database }}"
|
||||
- name: AUDIT_PG_TIMEZONE
|
||||
value: "{{ $root.Values.timezone | default "Asia/Shanghai" }}"
|
||||
# MQTT broker
|
||||
- name: AUDIT_MQTT_BROKER_URL
|
||||
value: "mqtt://{{ .Values.audit.mqtt.brokerHost }}:{{ .Values.audit.mqtt.brokerPort }}"
|
||||
- name: AUDIT_MQTT_CLIENT_ID
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: AUDIT_MQTT_SHARED_GROUP
|
||||
value: "mixingx-audit"
|
||||
# NanoMQ 管理 API
|
||||
- name: AUDIT_MQTT_MANAGEMENT_URL
|
||||
value: "http://{{ .Values.audit.mqtt.brokerHost }}:{{ .Values.audit.mqtt.managementPort }}"
|
||||
- name: AUDIT_MQTT_MANAGEMENT_USERNAME
|
||||
value: "{{ .Values.audit.mqtt.managementUsername }}"
|
||||
- name: AUDIT_MQTT_MANAGEMENT_PASSWORD
|
||||
value: "{{ .Values.audit.mqtt.managementPassword }}"
|
||||
# 消费队列/并发
|
||||
- name: AUDIT_CONSUME_QUEUE_CAPACITY
|
||||
value: "{{ .Values.audit.consume.queueCapacity }}"
|
||||
- name: AUDIT_CONSUME_QUEUE_MAX_WAIT_MS
|
||||
value: "{{ .Values.audit.consume.queueMaxWaitMs }}"
|
||||
- name: AUDIT_DB_WRITE_TIMEOUT_MS
|
||||
value: "{{ .Values.audit.consume.dbWriteTimeoutMs }}"
|
||||
- name: AUDIT_CONSUME_CONCURRENCY
|
||||
value: "{{ .Values.audit.consume.concurrency }}"
|
||||
# JWT
|
||||
- name: JWT_ISSUER
|
||||
value: "{{ .Values.audit.jwt.issuer }}"
|
||||
- name: JWT_AUDIENCE
|
||||
value: "{{ .Values.audit.jwt.audience }}"
|
||||
# OpenTelemetry
|
||||
- name: OTEL_EXPORTER_OTLP_ENDPOINT
|
||||
value: "{{ .Values.sharedInfra.otlp.endpoint }}"
|
||||
value: "{{ $root.Values.sharedInfra.otlp.endpoint }}"
|
||||
- name: OTEL_SERVICE_NAME
|
||||
value: "audit"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health/live
|
||||
port: http
|
||||
initialDelaySeconds: 15
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health/ready
|
||||
port: http
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
|
||||
@@ -3,25 +3,38 @@ tag: latest
|
||||
timezone: Asia/Shanghai
|
||||
|
||||
sharedInfra:
|
||||
mongo:
|
||||
host: mongo-service
|
||||
port: 27017
|
||||
username: admin
|
||||
postgres:
|
||||
image: docker.io/library/postgres:17
|
||||
username: postgres
|
||||
password: "Admin12345"
|
||||
database: mixingx_audit
|
||||
rabbitmq:
|
||||
host: messaging-service
|
||||
port: 5672
|
||||
username: guest
|
||||
password: guest
|
||||
port: 5432
|
||||
otlp:
|
||||
endpoint: http://k8s-dashboard-service:18889
|
||||
protocol: grpc
|
||||
|
||||
audit:
|
||||
enabled: true
|
||||
port: 5600
|
||||
port: 5900
|
||||
replicas: 2
|
||||
database: audit-db
|
||||
pgStorage: 5Gi
|
||||
# MQTT broker (中心 Audit NanoMQ)
|
||||
mqtt:
|
||||
brokerHost: "audit-nanomq-service"
|
||||
brokerPort: 1883
|
||||
managementPort: 8081
|
||||
managementUsername: "admin"
|
||||
managementPassword: "public"
|
||||
# JWT 鉴权(通过 SSO JWKS)
|
||||
jwt:
|
||||
issuer: "mixingx-sso"
|
||||
audience: "mixingx-audit"
|
||||
# 消费队列/并发配置
|
||||
consume:
|
||||
queueCapacity: 128
|
||||
queueMaxWaitMs: 5000
|
||||
dbWriteTimeoutMs: 3000
|
||||
concurrency: 4
|
||||
|
||||
images:
|
||||
audit:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{{- if .Values.audit.enabled }}
|
||||
{{- $root := $ }}
|
||||
---
|
||||
# ===== Audit 后端 (Node.js/Fastify, 端口 5900) =====
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
@@ -9,7 +10,7 @@ metadata:
|
||||
app.kubernetes.io/name: mixingx
|
||||
app.kubernetes.io/component: audit
|
||||
spec:
|
||||
replicas: {{ .Values.audit.replicas | default 1 }}
|
||||
replicas: {{ .Values.audit.replicas | default 2 }}
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/component: audit
|
||||
@@ -30,20 +31,66 @@ spec:
|
||||
env:
|
||||
- name: TZ
|
||||
value: "{{ $root.Values.timezone | default "Asia/Shanghai" }}"
|
||||
- name: MONGODB_URI
|
||||
value: "mongodb://{{ .Values.sharedInfra.mongo.username }}:{{ .Values.sharedInfra.mongo.password }}@{{ .Values.sharedInfra.mongo.host }}:{{ .Values.sharedInfra.mongo.port }}"
|
||||
- name: MONGODB_DATABASE
|
||||
value: "{{ .Values.sharedInfra.mongo.database }}"
|
||||
- name: RABBITMQ_URI
|
||||
value: "amqp://{{ .Values.sharedInfra.rabbitmq.username }}:{{ .Values.sharedInfra.rabbitmq.password }}@{{ .Values.sharedInfra.rabbitmq.host }}:{{ .Values.sharedInfra.rabbitmq.port }}"
|
||||
- name: PORT
|
||||
value: "{{ .Values.audit.port }}"
|
||||
- name: HOST
|
||||
value: "0.0.0.0"
|
||||
# PostgreSQL (仅 Audit 数据)
|
||||
- name: AUDIT_PG_URI
|
||||
value: "postgresql://{{ $root.Values.sharedInfra.postgres.username }}:{{ $root.Values.sharedInfra.postgres.password }}@{{ .Values.audit.database }}-postgres-service:{{ $root.Values.sharedInfra.postgres.port }}/{{ .Values.audit.database }}"
|
||||
- name: AUDIT_PG_TIMEZONE
|
||||
value: "{{ $root.Values.timezone | default "Asia/Shanghai" }}"
|
||||
# MQTT broker (中心 audit-nanomq)
|
||||
- name: AUDIT_MQTT_BROKER_URL
|
||||
value: "mqtt://{{ .Values.audit.mqtt.brokerHost }}:{{ .Values.audit.mqtt.brokerPort }}"
|
||||
- name: AUDIT_MQTT_CLIENT_ID
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: AUDIT_MQTT_SHARED_GROUP
|
||||
value: "mixingx-audit"
|
||||
# NanoMQ 管理 API (用于状态聚合)
|
||||
- name: AUDIT_MQTT_MANAGEMENT_URL
|
||||
value: "http://{{ .Values.audit.mqtt.brokerHost }}:{{ .Values.audit.mqtt.managementPort }}"
|
||||
- name: AUDIT_MQTT_MANAGEMENT_USERNAME
|
||||
value: "{{ .Values.audit.mqtt.managementUsername }}"
|
||||
- name: AUDIT_MQTT_MANAGEMENT_PASSWORD
|
||||
value: "{{ .Values.audit.mqtt.managementPassword }}"
|
||||
# 消费队列/并发配置
|
||||
- name: AUDIT_CONSUME_QUEUE_CAPACITY
|
||||
value: "128"
|
||||
- name: AUDIT_CONSUME_QUEUE_MAX_WAIT_MS
|
||||
value: "5000"
|
||||
- name: AUDIT_DB_WRITE_TIMEOUT_MS
|
||||
value: "3000"
|
||||
- name: AUDIT_CONSUME_CONCURRENCY
|
||||
value: "4"
|
||||
# JWT 鉴权 (SSO JWKS)
|
||||
- name: JWT_ISSUER
|
||||
value: "{{ .Values.audit.jwt.issuer }}"
|
||||
- name: JWT_AUDIENCE
|
||||
value: "{{ .Values.audit.jwt.audience }}"
|
||||
- name: JWT_JWKS_URI
|
||||
value: "http://sso-service:5100/.well-known/jwks.json"
|
||||
# OpenTelemetry
|
||||
- name: OTEL_EXPORTER_OTLP_ENDPOINT
|
||||
value: "{{ .Values.sharedInfra.otlp.endpoint }}"
|
||||
value: "{{ $root.Values.sharedInfra.otlp.endpoint }}"
|
||||
- name: OTEL_SERVICE_NAME
|
||||
value: "audit"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health/live
|
||||
port: http
|
||||
initialDelaySeconds: 15
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health/ready
|
||||
port: http
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
@@ -54,6 +101,8 @@ metadata:
|
||||
app.kubernetes.io/component: audit
|
||||
mixingx.io/role: audit
|
||||
mixingx.io/node-id: audit
|
||||
annotations:
|
||||
mixingx.io/description: "审计服务"
|
||||
spec:
|
||||
selector:
|
||||
app.kubernetes.io/component: audit
|
||||
@@ -62,4 +111,125 @@ spec:
|
||||
port: {{ .Values.audit.port }}
|
||||
targetPort: http
|
||||
protocol: TCP
|
||||
---
|
||||
# ===== Audit 前端 (nginx, 端口 8900) =====
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ .Values.audit.webName }}-deployment
|
||||
labels:
|
||||
app.kubernetes.io/name: mixingx
|
||||
app.kubernetes.io/component: {{ .Values.audit.webName }}
|
||||
spec:
|
||||
replicas: {{ .Values.audit.replicas | default 2 }}
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/component: {{ .Values.audit.webName }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: {{ .Values.audit.webName }}
|
||||
spec:
|
||||
{{ include "mixingx-platform.tierAffinity" (dict "role" "audit" "root" $root) | nindent 6 }}
|
||||
containers:
|
||||
- name: {{ .Values.audit.webName }}
|
||||
image: "{{ .Values.registry }}/{{ .Values.audit.webImage }}:{{ .Values.tag | default "latest" }}"
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: {{ .Values.audit.webPort }}
|
||||
protocol: TCP
|
||||
env:
|
||||
- name: TZ
|
||||
value: "{{ $root.Values.timezone | default "Asia/Shanghai" }}"
|
||||
- name: VITE_BASE_PATH
|
||||
value: "{{ .Values.audit.webBasePath }}"
|
||||
- name: PORT
|
||||
value: "{{ .Values.audit.webPort }}"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ .Values.audit.webName }}-service
|
||||
labels:
|
||||
app.kubernetes.io/name: mixingx
|
||||
app.kubernetes.io/component: {{ .Values.audit.webName }}
|
||||
mixingx.io/role: web
|
||||
mixingx.io/node-id: {{ .Values.audit.webName }}
|
||||
spec:
|
||||
selector:
|
||||
app.kubernetes.io/component: {{ .Values.audit.webName }}
|
||||
ports:
|
||||
- name: http
|
||||
port: {{ .Values.audit.webPort }}
|
||||
targetPort: http
|
||||
protocol: TCP
|
||||
---
|
||||
# ===== Audit PostgreSQL =====
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: {{ .Values.audit.database }}-postgres
|
||||
labels:
|
||||
app.kubernetes.io/name: mixingx
|
||||
app.kubernetes.io/component: {{ .Values.audit.database }}-postgres
|
||||
spec:
|
||||
serviceName: {{ .Values.audit.database }}-postgres-service
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/component: {{ .Values.audit.database }}-postgres
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
annotations:
|
||||
helm.sh/resource-policy: keep
|
||||
spec:
|
||||
accessModes: ["ReadWriteOnce"]
|
||||
storageClassName: {{ include "mixingx-platform.storageClassName" $root }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.audit.pgStorage }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: {{ .Values.audit.database }}-postgres
|
||||
spec:
|
||||
{{ include "mixingx-platform.tierAffinity" (dict "role" "audit" "root" $root) | nindent 6 }}
|
||||
containers:
|
||||
- name: postgres
|
||||
image: {{ $root.Values.sharedInfra.postgres.image | default "docker.io/library/postgres:17" }}
|
||||
imagePullPolicy: IfNotPresent
|
||||
env:
|
||||
- name: POSTGRES_PASSWORD
|
||||
value: "{{ $root.Values.sharedInfra.postgres.password }}"
|
||||
- name: POSTGRES_DB
|
||||
value: "{{ .Values.audit.database }}"
|
||||
- name: POSTGRES_USER
|
||||
value: "{{ $root.Values.sharedInfra.postgres.username }}"
|
||||
- name: PGDATA
|
||||
value: /var/lib/postgresql/data/pgdata
|
||||
ports:
|
||||
- name: tcp
|
||||
containerPort: {{ $root.Values.sharedInfra.postgres.port }}
|
||||
protocol: TCP
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ .Values.audit.database }}-postgres-service
|
||||
labels:
|
||||
app.kubernetes.io/name: mixingx
|
||||
app.kubernetes.io/component: {{ .Values.audit.database }}-postgres
|
||||
spec:
|
||||
selector:
|
||||
app.kubernetes.io/component: {{ .Values.audit.database }}-postgres
|
||||
ports:
|
||||
- name: tcp
|
||||
port: {{ $root.Values.sharedInfra.postgres.port }}
|
||||
targetPort: tcp
|
||||
protocol: TCP
|
||||
{{- end }}
|
||||
@@ -59,6 +59,25 @@ spec:
|
||||
- name: RABBITMQ_DEFAULT_PASS
|
||||
value: "{{ $root.Values.sharedInfra.rabbitmq.password }}"
|
||||
{{- end }}
|
||||
{{- if eq .name "audit-nanomq" }}
|
||||
command: ["/bin/sh"]
|
||||
args:
|
||||
- "-c"
|
||||
- |
|
||||
cat > /etc/nanomq.conf <<EOF
|
||||
mqtt {
|
||||
allow_anonymous = true
|
||||
max_mqueue_len = 128
|
||||
}
|
||||
http_server {
|
||||
enable = true
|
||||
port = 8081
|
||||
username = {{ $root.Values.audit.mqtt.managementUsername }}
|
||||
password = {{ $root.Values.audit.mqtt.managementPassword }}
|
||||
}
|
||||
EOF
|
||||
exec nanomq start --conf /etc/nanomq.conf
|
||||
{{- end }}
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: {{ .mountPath }}
|
||||
@@ -84,4 +103,14 @@ spec:
|
||||
targetPort: 15672
|
||||
protocol: TCP
|
||||
{{- end }}
|
||||
{{- if eq .name "audit-nanomq" }}
|
||||
- name: mqtt
|
||||
port: {{ $root.Values.audit.mqtt.brokerPort }}
|
||||
targetPort: {{ $root.Values.audit.mqtt.brokerPort }}
|
||||
protocol: TCP
|
||||
- name: management
|
||||
port: {{ $root.Values.audit.mqtt.managementPort }}
|
||||
targetPort: {{ $root.Values.audit.mqtt.managementPort }}
|
||||
protocol: TCP
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -74,8 +74,25 @@ gateway:
|
||||
audit:
|
||||
enabled: true
|
||||
image: audit
|
||||
port: 5600
|
||||
port: 5900
|
||||
replicas: 2
|
||||
webName: audit-web
|
||||
webImage: audit-web
|
||||
webBasePath: /audit/
|
||||
webPort: 8900
|
||||
database: audit-db
|
||||
pgStorage: 5Gi
|
||||
# MQTT broker (中心 Audit NanoMQ)
|
||||
mqtt:
|
||||
brokerHost: "audit-nanomq-service"
|
||||
brokerPort: 1883
|
||||
managementPort: 8081
|
||||
managementUsername: "admin"
|
||||
managementPassword: "public"
|
||||
# JWT 鉴权(通过 SSO JWKS)
|
||||
jwt:
|
||||
issuer: "mixingx-sso"
|
||||
audience: "mixingx-audit"
|
||||
|
||||
sharedDatastores:
|
||||
- name: redis
|
||||
@@ -93,6 +110,12 @@ sharedDatastores:
|
||||
port: 5672
|
||||
storage: 2Gi
|
||||
mountPath: /var/lib/rabbitmq
|
||||
- name: audit-nanomq
|
||||
image: emqx/nanomq:0.25.2-2
|
||||
port: 1883
|
||||
storage: 1Gi
|
||||
mountPath: /var/lib/nanomq
|
||||
managementPort: 8081
|
||||
|
||||
ingress:
|
||||
enabled: true
|
||||
|
||||
Reference in new issue
Block a user