重大变更:
- .drone.yml: 4 步 pipeline(submodule init → build 12 镜像 → helm deploy → verify)
- mixingx-chart/: 手写 Helm chart(模式 3,替代 aspire publish)
- 独立 postgres(每服务一个,不再共享)
- 四胞胎架构(agent/edge: 后端+前端+DB podAffinity 同节点)
- pgAdmin(在 K3s 内,管理所有 postgres)
- Aspire Dashboard(OTLP 遥测接收端)
- Dockerfile: 全部服务已补齐(含 gateway/audit 新增)
- apphost.cs: opcua mock publish 模式改 AddDockerfile
- patch-persistence.sh: emptyDir → PVC patch(备用)
submodule 指针更新:
- mixingx.sso: Dockerfile 精准 COPY
- mixingx.edge: opcua Dockerfile 新增
- eau.ultra: MigrateAsync 无条件执行
- mixingx.audit: Dockerfile 新增
- mixingx.gateway: Dockerfile 新增
镜像 tag 规则: {分支}-{时间戳}-[{tag}]
154 lines
5.4 KiB
Smarty
154 lines
5.4 KiB
Smarty
{{/*
|
|
公共模板:后端 Deployment + Service + ConfigMap + Secret
|
|
连接串指向独立 postgres({name}-postgres-service)
|
|
|
|
参数:
|
|
name - 服务名
|
|
image - 镜像名
|
|
port - 端口(默认 8080)
|
|
role - mixingx.io/role
|
|
replicas - 副本数(默认 1)
|
|
serviceId - 业务身份(可选)
|
|
database - 数据库名(有则生成 PG 连接串,指向 {name}-postgres-service)
|
|
rbac - 是否需要 serviceAccount(只有 gateway)
|
|
root - $ (root context)
|
|
*/}}
|
|
{{- define "mixingx.backend" -}}
|
|
{{- $root := .root -}}
|
|
{{- $port := .port | default 8080 -}}
|
|
{{- $pgHost := printf "%s-postgres-service" .name -}}
|
|
---
|
|
# Deployment: {{ .name }}
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: {{ .name }}-deployment
|
|
labels:
|
|
app.kubernetes.io/name: mixingx
|
|
app.kubernetes.io/instance: {{ $root.Release.Name }}
|
|
app.kubernetes.io/component: {{ .name }}
|
|
spec:
|
|
replicas: {{ .replicas | default 1 }}
|
|
selector:
|
|
matchLabels:
|
|
app.kubernetes.io/component: {{ .name }}
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app.kubernetes.io/component: {{ .name }}
|
|
spec:
|
|
{{- if .rbac }}
|
|
serviceAccountName: gateway-sa
|
|
{{- end }}
|
|
containers:
|
|
- name: {{ .name }}
|
|
image: {{ $root.Values.registry }}/{{ .image }}:{{ $root.Values.tag | default "latest" }}
|
|
imagePullPolicy: IfNotPresent
|
|
ports:
|
|
- name: http
|
|
containerPort: {{ $port }}
|
|
protocol: TCP
|
|
envFrom:
|
|
- configMapRef:
|
|
name: {{ .name }}-config
|
|
- secretRef:
|
|
name: {{ .name }}-secrets
|
|
{{- if .rbac }}
|
|
env:
|
|
- name: POD_NAMESPACE
|
|
valueFrom:
|
|
fieldRef:
|
|
fieldPath: metadata.namespace
|
|
{{- end }}
|
|
livenessProbe:
|
|
httpGet:
|
|
path: /health
|
|
port: http
|
|
scheme: HTTP
|
|
initialDelaySeconds: 15
|
|
periodSeconds: 30
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /alive
|
|
port: http
|
|
scheme: HTTP
|
|
initialDelaySeconds: 5
|
|
periodSeconds: 10
|
|
|
|
---
|
|
# Service: {{ .name }}
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: {{ .name }}-service
|
|
labels:
|
|
app.kubernetes.io/name: mixingx
|
|
app.kubernetes.io/component: {{ .name }}
|
|
{{- if and .role (ne .role "gateway") }}
|
|
mixingx.io/role: {{ .role }}
|
|
mixingx.io/node-id: {{ .name }}
|
|
{{- end }}
|
|
spec:
|
|
selector:
|
|
app.kubernetes.io/component: {{ .name }}
|
|
ports:
|
|
- name: http
|
|
port: {{ $port }}
|
|
targetPort: http
|
|
protocol: TCP
|
|
|
|
---
|
|
# ConfigMap: {{ .name }}
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: {{ .name }}-config
|
|
data:
|
|
HTTP_PORTS: "{{ $port }}"
|
|
REDIS_HOST: "{{ $root.Values.sharedInfra.redis.host }}"
|
|
REDIS_PORT: "{{ $root.Values.sharedInfra.redis.port }}"
|
|
POSTGRESQL_HOST: "{{ $pgHost }}"
|
|
POSTGRESQL_PORT: "{{ $root.Values.sharedInfra.postgres.port }}"
|
|
POSTGRESQL_USERNAME: "{{ $root.Values.sharedInfra.postgres.username }}"
|
|
MESSAGING_HOST: "{{ $root.Values.sharedInfra.rabbitmq.host }}"
|
|
MESSAGING_PORT: "{{ $root.Values.sharedInfra.rabbitmq.port }}"
|
|
MESSAGING_USERNAME: "{{ $root.Values.sharedInfra.rabbitmq.username }}"
|
|
{{- if not .rbac }}
|
|
services__gateway__http__0: "http://gateway-service:8080"
|
|
{{- end }}
|
|
{{- if .serviceId }}
|
|
{{- if hasPrefix "agent" .name }}
|
|
AGENT_SERVICE_ID: "{{ .serviceId }}"
|
|
{{- else if hasPrefix "edge" .name }}
|
|
EDGE_SERVICE_ID: "{{ .serviceId }}"
|
|
{{- else if hasPrefix "sso" .name }}
|
|
SSO_SERVICE_ID: "{{ .serviceId }}"
|
|
{{- end }}
|
|
{{- end }}
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: "{{ $root.Values.sharedInfra.otlp.endpoint }}"
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: "{{ $root.Values.sharedInfra.otlp.protocol }}"
|
|
OTEL_SERVICE_NAME: "{{ .name }}"
|
|
ASPNETCORE_FORWARDEDHEADERS_ENABLED: "true"
|
|
|
|
---
|
|
# Secret: {{ .name }}
|
|
apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: {{ .name }}-secrets
|
|
type: Opaque
|
|
stringData:
|
|
ConnectionStrings__redis: "{{ $root.Values.sharedInfra.redis.host }}:{{ $root.Values.sharedInfra.redis.port }},password={{ $root.Values.sharedInfra.redis.password }}"
|
|
REDIS_PASSWORD: "{{ $root.Values.sharedInfra.redis.password }}"
|
|
REDIS_URI: "redis://:{{ $root.Values.sharedInfra.redis.password }}@{{ $root.Values.sharedInfra.redis.host }}:{{ $root.Values.sharedInfra.redis.port }}"
|
|
{{- if .database }}
|
|
ConnectionStrings__PostgreSQL: "Host={{ $pgHost }};Port={{ $root.Values.sharedInfra.postgres.port }};Username={{ $root.Values.sharedInfra.postgres.username }};Password={{ $root.Values.sharedInfra.postgres.password }};Database={{ .database }}"
|
|
POSTGRESQL_PASSWORD: "{{ $root.Values.sharedInfra.postgres.password }}"
|
|
POSTGRESQL_URI: "postgresql://{{ $root.Values.sharedInfra.postgres.username }}:{{ $root.Values.sharedInfra.postgres.password }}@{{ $pgHost }}:{{ $root.Values.sharedInfra.postgres.port }}/{{ .database }}"
|
|
POSTGRESQL_DATABASENAME: "{{ .database }}"
|
|
{{- end }}
|
|
ConnectionStrings__messaging: "amqp://{{ $root.Values.sharedInfra.rabbitmq.username }}:{{ $root.Values.sharedInfra.rabbitmq.password }}@{{ $root.Values.sharedInfra.rabbitmq.host }}:{{ $root.Values.sharedInfra.rabbitmq.port }}"
|
|
MESSAGING_PASSWORD: "{{ $root.Values.sharedInfra.rabbitmq.password }}"
|
|
MESSAGING_URI: "amqp://{{ $root.Values.sharedInfra.rabbitmq.username }}:{{ $root.Values.sharedInfra.rabbitmq.password }}@{{ $root.Values.sharedInfra.rabbitmq.host }}:{{ $root.Values.sharedInfra.rabbitmq.port }}"
|
|
{{- end -}}
|