From 5e83675edf0348f19d65c0416a208ed0421a3b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=87=8E?= Date: Sun, 2 Aug 2026 23:47:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(gateway):=20=E6=B7=BB=E5=8A=A0mqtt-bro?= =?UTF-8?q?ker=E6=9C=8D=E5=8A=A1=E5=8F=91=E7=8E=B0=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gateway需要读取Service列表来发现edge/agent等后端及mqtt-broker(Task 07) 权限仅包含Service的get/list/watch操作,不涉及Pod/Secret/ConfigMap --- release-charts/mixingx-gateway/templates/gateway-rbac.yaml | 2 ++ release-charts/mixingx-platform/templates/gateway-rbac.yaml | 2 ++ templates/gateway-rbac.yaml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/release-charts/mixingx-gateway/templates/gateway-rbac.yaml b/release-charts/mixingx-gateway/templates/gateway-rbac.yaml index d3ba6d0..f13bb41 100644 --- a/release-charts/mixingx-gateway/templates/gateway-rbac.yaml +++ b/release-charts/mixingx-gateway/templates/gateway-rbac.yaml @@ -1,3 +1,5 @@ +{{/* Gateway 需要读 Service 列表来发现 edge/agent 等后端及 mqtt-broker(Task 07) */}} +{{/* 权限只有 Service get/list/watch,不包含 Pod/Secret/ConfigMap */}} {{- if .Values.gateway.rbac }} --- apiVersion: v1 diff --git a/release-charts/mixingx-platform/templates/gateway-rbac.yaml b/release-charts/mixingx-platform/templates/gateway-rbac.yaml index d3ba6d0..f13bb41 100644 --- a/release-charts/mixingx-platform/templates/gateway-rbac.yaml +++ b/release-charts/mixingx-platform/templates/gateway-rbac.yaml @@ -1,3 +1,5 @@ +{{/* Gateway 需要读 Service 列表来发现 edge/agent 等后端及 mqtt-broker(Task 07) */}} +{{/* 权限只有 Service get/list/watch,不包含 Pod/Secret/ConfigMap */}} {{- if .Values.gateway.rbac }} --- apiVersion: v1 diff --git a/templates/gateway-rbac.yaml b/templates/gateway-rbac.yaml index db5ab4f..83120f6 100644 --- a/templates/gateway-rbac.yaml +++ b/templates/gateway-rbac.yaml @@ -1,6 +1,8 @@ {{/* Gateway K8s 服务发现 RBAC gateway 需要读 Service 列表(查 mixingx.io/role 标签)来发现 agent/edge 等 +包括 mqtt-broker Service(查 mixingx.io/role=mqtt-broker,Task 07) +权限只有 Service get/list/watch,不包含 Pod/Secret/ConfigMap */}} --- apiVersion: v1 From 28011f115421ea94891e7e291ffae62293833b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=87=8E?= Date: Mon, 3 Aug 2026 00:30:03 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(unit):=20=E6=B7=BB=E5=8A=A0MQTT?= =?UTF-8?q?=E5=87=AD=E6=8D=AE=E9=85=8D=E7=BD=AE=E5=92=8CNanoMQ=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在mixingx-agent-unit中添加mqttCredentials配置项,用于存储MQTT凭据映射表 - 在unit.yaml模板中添加MQTT凭据相关的环境变量配置循环 - 为mixingx-edge-unit添加NanoMQ代理的服务名称和凭据引用的helper模板 - 配置Edge单元的MQTT相关环境变量(Mqtt__BrokerHost、Mqtt__BrokerPort、Mqtt__Enabled) - 添加NanoMQ代理的镜像配置、端口和资源配置选项 --- .../mixingx-agent-unit/templates/unit.yaml | 4 ++ release-charts/mixingx-agent-unit/values.yaml | 8 +++ .../mixingx-edge-unit/templates/_helpers.tpl | 15 +++++ .../mixingx-edge-unit/templates/nanomq.yaml | 57 +++++++++++++++++++ .../mixingx-edge-unit/templates/unit.yaml | 4 ++ release-charts/mixingx-edge-unit/values.yaml | 9 +++ 6 files changed, 97 insertions(+) create mode 100644 release-charts/mixingx-edge-unit/templates/nanomq.yaml diff --git a/release-charts/mixingx-agent-unit/templates/unit.yaml b/release-charts/mixingx-agent-unit/templates/unit.yaml index 90f4e8a..b1fbb39 100644 --- a/release-charts/mixingx-agent-unit/templates/unit.yaml +++ b/release-charts/mixingx-agent-unit/templates/unit.yaml @@ -121,6 +121,10 @@ stringData: 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 }} + Mqtt__Credentials__{{ .credentialRef }}__Username: "{{ .username }}" + Mqtt__Credentials__{{ .credentialRef }}__Password: "{{ .password }}" + {{- end }} --- apiVersion: apps/v1 kind: Deployment diff --git a/release-charts/mixingx-agent-unit/values.yaml b/release-charts/mixingx-agent-unit/values.yaml index 2b36f40..49901cf 100644 --- a/release-charts/mixingx-agent-unit/values.yaml +++ b/release-charts/mixingx-agent-unit/values.yaml @@ -52,3 +52,11 @@ sharedInfra: otlp: endpoint: http://k8s-dashboard-service:18889 protocol: grpc + +# credentialRef → credential 映射表。 +# Agent 从 Gateway descriptor 获取每个 Edge 的 credentialRef, +# 再从此表查找对应的 MQTT 用户名/密码。 +mqttCredentials: [] +# - credentialRef: "edge-demo-mqtt" +# username: "edge-user" +# password: "edge-pass" diff --git a/release-charts/mixingx-edge-unit/templates/_helpers.tpl b/release-charts/mixingx-edge-unit/templates/_helpers.tpl index a2bfe98..02f7ed8 100644 --- a/release-charts/mixingx-edge-unit/templates/_helpers.tpl +++ b/release-charts/mixingx-edge-unit/templates/_helpers.tpl @@ -49,3 +49,18 @@ affinity: topologyKey: kubernetes.io/hostname {{- end }} {{- end -}} + +{{- define "mixingx-unit.mqttBrokerName" -}} +{{- $name := include "mixingx-unit.name" . -}} +{{- printf "%s-nanomq" $name -}} +{{- end -}} + +{{- define "mixingx-unit.mqttBrokerServiceName" -}} +{{- $name := include "mixingx-unit.name" . -}} +{{- printf "%s-nanomq-service" $name -}} +{{- end -}} + +{{- define "mixingx-unit.mqttCredentialRef" -}} +{{- $name := include "mixingx-unit.name" . -}} +{{- .Values.mqtt.credentialRef | default (printf "%s-mqtt" $name) -}} +{{- end -}} diff --git a/release-charts/mixingx-edge-unit/templates/nanomq.yaml b/release-charts/mixingx-edge-unit/templates/nanomq.yaml new file mode 100644 index 0000000..7ed8169 --- /dev/null +++ b/release-charts/mixingx-edge-unit/templates/nanomq.yaml @@ -0,0 +1,57 @@ +{{- $name := include "mixingx-unit.name" . -}} +{{- $brokerName := include "mixingx-unit.mqttBrokerName" . -}} +{{- $brokerSvcName := include "mixingx-unit.mqttBrokerServiceName" . -}} +{{- $credentialRef := include "mixingx-unit.mqttCredentialRef" . -}} +{{- if .Values.mqtt.enabled }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ $brokerName }} + labels: + app.kubernetes.io/name: mixingx + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/component: {{ $brokerName }} +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/component: {{ $brokerName }} + template: + metadata: + labels: + app.kubernetes.io/component: {{ $brokerName }} + spec: +{{ include "mixingx-unit.backendScheduling" . | nindent 6 }} + containers: + - name: nanomq + image: "{{ .Values.mqtt.image.repository }}:{{ .Values.mqtt.image.tag }}" + imagePullPolicy: IfNotPresent + ports: + - name: mqtt + containerPort: {{ .Values.mqtt.port }} + protocol: TCP + resources: +{{ toYaml .Values.mqtt.resources | default dict | nindent 12 }} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ $brokerSvcName }} + labels: + app.kubernetes.io/name: mixingx + app.kubernetes.io/component: {{ $brokerName }} + mixingx.io/role: mqtt-broker + mixingx.io/node-id: {{ $name }} + annotations: + mixingx.io/credential-ref: {{ $credentialRef }} +spec: + type: ClusterIP + selector: + app.kubernetes.io/component: {{ $brokerName }} + ports: + - name: mqtt + port: {{ .Values.mqtt.port }} + targetPort: mqtt + protocol: TCP +{{- end }} diff --git a/release-charts/mixingx-edge-unit/templates/unit.yaml b/release-charts/mixingx-edge-unit/templates/unit.yaml index a97a28b..0154c0a 100644 --- a/release-charts/mixingx-edge-unit/templates/unit.yaml +++ b/release-charts/mixingx-edge-unit/templates/unit.yaml @@ -4,6 +4,7 @@ {{- $serviceId := include "mixingx-unit.serviceId" . -}} {{- $basePath := include "mixingx-unit.basePath" . -}} {{- $pgHost := printf "%s-postgres-service" $name -}} +{{- $brokerSvcName := include "mixingx-unit.mqttBrokerServiceName" . -}} --- apiVersion: apps/v1 kind: Deployment @@ -100,6 +101,9 @@ data: OTEL_EXPORTER_OTLP_ENDPOINT: "{{ .Values.sharedInfra.otlp.endpoint }}" OTEL_EXPORTER_OTLP_PROTOCOL: "{{ .Values.sharedInfra.otlp.protocol }}" OTEL_SERVICE_NAME: "{{ $name }}" + Mqtt__BrokerHost: "{{ $brokerSvcName }}" + Mqtt__BrokerPort: "{{ .Values.mqtt.port }}" + Mqtt__Enabled: "true" ASPNETCORE_FORWARDEDHEADERS_ENABLED: "true" --- apiVersion: v1 diff --git a/release-charts/mixingx-edge-unit/values.yaml b/release-charts/mixingx-edge-unit/values.yaml index a1b392c..b2f3087 100644 --- a/release-charts/mixingx-edge-unit/values.yaml +++ b/release-charts/mixingx-edge-unit/values.yaml @@ -51,3 +51,12 @@ sharedInfra: otlp: endpoint: http://k8s-dashboard-service:18889 protocol: grpc + +mqtt: + enabled: true + image: + repository: emqx/nanomq + tag: 0.25.2-2 + port: 1883 + credentialRef: "" # 默认空,模板内 default 为 {name}-mqtt + resources: {} From 7d6a034392975eac217805d156e03ea43f228cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=87=8E?= Date: Tue, 4 Aug 2026 13:24:00 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(mixingx-agent-unit):=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0MQTT=E9=85=8D=E7=BD=AE=E9=A1=B9=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复MQTT凭据配置项的命名,将前缀从"Mqtt__Credentials__"更改为"AgentEdgeMqtt__Credentials__" 以符合新的配置规范,确保用户名字段名正确映射为UserName格式。 --- release-charts/mixingx-agent-unit/templates/unit.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release-charts/mixingx-agent-unit/templates/unit.yaml b/release-charts/mixingx-agent-unit/templates/unit.yaml index b1fbb39..d043309 100644 --- a/release-charts/mixingx-agent-unit/templates/unit.yaml +++ b/release-charts/mixingx-agent-unit/templates/unit.yaml @@ -122,8 +122,8 @@ stringData: 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 }} - Mqtt__Credentials__{{ .credentialRef }}__Username: "{{ .username }}" - Mqtt__Credentials__{{ .credentialRef }}__Password: "{{ .password }}" + AgentEdgeMqtt__Credentials__{{ .credentialRef }}__UserName: "{{ .username }}" + AgentEdgeMqtt__Credentials__{{ .credentialRef }}__Password: "{{ .password }}" {{- end }} --- apiVersion: apps/v1 From 38907081abaa3ae5eebb19ba1ce630a73a39fe9b Mon Sep 17 00:00:00 2001 From: ximenchuifeng Date: Wed, 5 Aug 2026 10:21:07 +0800 Subject: [PATCH 4/4] =?UTF-8?q?chore(chart):=20=E7=A7=BB=E9=99=A4=E5=BA=9F?= =?UTF-8?q?=E5=BC=83=E7=9A=84=E5=8D=95=E4=BD=93=E4=B8=BB=20chart,=E4=BB=85?= =?UTF-8?q?=E4=BF=9D=E7=95=99=20release-charts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除根 Chart.yaml/values.yaml/values-105.yaml 和 templates/(19 文件) - 这些单体 chart 是早期"替代 Aspire publish"的尝试,已被 release-charts/ 取代 - CI(.drone.yml)和 ArgoCD(mixingx-deploy)均只使用 release-charts/ - release-charts 有独立 _helpers.tpl,不依赖主 chart 的任何模板 - README 改写为只描述 release-charts 部署入口 --- Chart.yaml | 6 -- README.md | 111 +++++---------------- templates/_backend.tpl | 177 --------------------------------- templates/_frontend.tpl | 93 ----------------- templates/_helpers.tpl | 30 ------ templates/_point-affinity.tpl | 81 --------------- templates/_postgres.tpl | 102 ------------------- templates/_tier-affinity.tpl | 80 --------------- templates/app-ingress.yaml | 26 ----- templates/audit.yaml | 66 ------------ templates/backend-gateway.yaml | 1 - templates/dashboard.yaml | 67 ------------- templates/gateway-rbac.yaml | 38 ------- templates/instances.yaml | 54 ---------- templates/mock.yaml | 58 ----------- templates/pgadmin.yaml | 79 --------------- templates/shared-infra.yaml | 90 ----------------- templates/standalones.yaml | 18 ---- values-105.yaml | 15 --- values.yaml | 168 ------------------------------- 20 files changed, 23 insertions(+), 1337 deletions(-) delete mode 100644 Chart.yaml delete mode 100644 templates/_backend.tpl delete mode 100644 templates/_frontend.tpl delete mode 100644 templates/_helpers.tpl delete mode 100644 templates/_point-affinity.tpl delete mode 100644 templates/_postgres.tpl delete mode 100644 templates/_tier-affinity.tpl delete mode 100644 templates/app-ingress.yaml delete mode 100644 templates/audit.yaml delete mode 100644 templates/backend-gateway.yaml delete mode 100644 templates/dashboard.yaml delete mode 100644 templates/gateway-rbac.yaml delete mode 100644 templates/instances.yaml delete mode 100644 templates/mock.yaml delete mode 100644 templates/pgadmin.yaml delete mode 100644 templates/shared-infra.yaml delete mode 100644 templates/standalones.yaml delete mode 100644 values-105.yaml delete mode 100644 values.yaml diff --git a/Chart.yaml b/Chart.yaml deleted file mode 100644 index 4493167..0000000 --- a/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v2 -name: mixingx -description: MixingX 全栈部署 Helm Chart(替代 Aspire publish) -type: application -version: 1.2.0 -appVersion: "1.0.1" diff --git a/README.md b/README.md index 24f64d2..552f879 100644 --- a/README.md +++ b/README.md @@ -1,107 +1,42 @@ # MixingX.Hub.Chart -> Legacy note: repository root is the historical all-in-one chart. Keep it for compatibility while new GitOps releases migrate to the split charts under `release-charts/`. +本仓库以 git submodule 形式挂载在 [mixingx.hub](https://gitee.com/mixing-tech/mixingx.hub) 的 `mixingx-chart/` 路径下。CI(Drone)和 ArgoCD 都通过 `release-charts/` 子目录访问,改路径名会破坏部署链路。 -## Recommended Split Charts +## 拆分 Release Charts(唯一部署入口) -Use these charts for new Argo CD Applications: +所有部署(CI lint/template、ArgoCD Application)都使用 `release-charts/` 下的拆分 unit chart,不再有单体主 chart: -- `release-charts/mixingx-platform` - central platform services. -- `release-charts/mixingx-edge-unit` - one edge unit per Helm release. -- `release-charts/mixingx-agent-unit` - one agent unit per Helm release. +| Chart | 职责 | +|---|---| +| `release-charts/mixingx-infra` | 共享基础设施(redis/mongo/rabbitmq/postgres) | +| `release-charts/mixingx-platform` | 中央平台服务(sso/ultra/audit/gateway) | +| `release-charts/mixingx-edge-unit` | 单个 Edge 单元(后端+前端+独立 DB+NanoMQ broker) | +| `release-charts/mixingx-agent-unit` | 单个 Agent 单元(后端+前端+独立 DB) | +| `release-charts/mixingx-gateway` | Gateway(带 MQTT broker 发现 RBAC) | +| `release-charts/mixingx-sso` | SSO(独立发布) | +| `release-charts/mixingx-ultra` | Ultra(独立发布) | +| `release-charts/mixingx-audit` | Audit(独立发布) | +| `release-charts/mixingx-protocol-server-unit` | 协议模拟器单元 | -The root chart remains available for old CI/manual Helm flows, but new deployments should prefer the split release boundary so platform upgrades do not prune customer-added edge/agent units. - -MixingX 全栈部署 Helm Chart(替代 Aspire publish 生成器)。 - -- **name**: `mixingx` -- **version**: 1.2.0 -- **appVersion**: 1.0.1 - -本仓库以 git submodule 形式挂载在 [mixingx.hub](https://gitee.com/mixing-tech/mixingx.hub) 的 `mixingx-chart/` 路径下。CI(Drone)和本地 `helm` 命令都通过这个路径访问,改路径名会破坏部署链路。 - -## 架构:4 种服务类型 - -| 类型 | 服务 | 特点 | 数据源 | -|---|---|---|---| -| **A 四胞胎** | agent / edge | 后端+前端+独立DB,podAffinity 强制同节点 | `agents` / `edges` 数组 | -| **B standalones** | sso / ultra | 后端+前端+独立DB,无亲和,多副本 | `standalones` 数组 | -| **C 无DB** | gateway / audit | 单后端(gateway 带 RBAC;audit 连 Mongo) | `gateway` / `audit` 块 | -| **D 共享基础设施** | redis / mongo / rabbitmq | StatefulSet+PVC,所有服务共用 | `sharedDatastores` 数组 | - -每个有 DB 的服务各自独立 postgres(StatefulSet),连接串指向 `{name}-postgres-service`。 - -## 三层调度优先级 - -每个 Pod 的 `spec` 按以下优先级**只取一层**: - -``` -1. nodeName 直接指定节点(最高,跳过 scheduler) -2. pointAffinity 点位级 nodeAffinity(覆盖全局 tier) -3. tier 全局档位调度(tier.enabled=true 才生效) -4. 无 兜底,随便调度 -``` - -- **nodeName**:点位对象 `{site, nodeName}` → 跳过 scheduler。⚠️ 配合 local-path WaitForFirstConsumer 会触发 PVC 死循环(k8s#89953),生产建议用 nodeAffinity+label。 -- **pointAffinity**:点位对象 `{site, nodeAffinity: {required?, preferred?}}` → 原生 nodeAffinity,由 kube-node OpsPage 点位对话框编辑。 -- **tier**:给节点打 `mixingx.io/tier=infra|perf|edge` label,服务按角色声明要去哪档(`required` 硬约束 / `preferred` 软约束)。 - -前端/PG 因要和后端 podAffinity 同节点,合并 podAffinity + nodeAffinity 到同一个 `affinity:` 块(见 `_tier-affinity.tpl` / `_point-affinity.tpl` 的 NodeAffinity 变体)。 - -## 模板结构 - -``` -templates/ -├── _helpers.tpl # 镜像名/标签/服务发现标签 -├── _backend.tpl # 后端三件套(Deployment+Service+ConfigMap+Secret) -├── _frontend.tpl # 前端两件套(Deployment+Service) -├── _postgres.tpl # 独立 PG(StatefulSet+Service+PVC) -├── _tier-affinity.tpl # 全局 tier 调度(最底层) -├── _point-affinity.tpl # 点位 nodeAffinity(中层) -├── instances.yaml # 🔁 遍历 agents/edges → 调用三个公共模板 -├── standalones.yaml # 🔁 遍历 standalones(sso/ultra) -├── backend-gateway.yaml # gateway(单例,带 RBAC) -├── audit.yaml # audit(独立模板,连 Mongo) -├── shared-infra.yaml # 🔁 redis/mongo/rabbitmq -├── mock.yaml # 🔁 协议模拟器 -├── dashboard.yaml # Aspire OTLP Dashboard -├── pgadmin.yaml # pgAdmin + 独立 Ingress -├── app-ingress.yaml # 业务总 Ingress(→ gateway) -└── gateway-rbac.yaml # gateway SA + Role + RoleBinding -``` +每个 chart 独立 `helm release`,平台升级不会误删客户自加的 edge/agent 单元。 ## 使用 -### 打包发布 +### CI(Drone)lint + template + +CI 只对 `release-charts/` 做 lint/template(见 hub `.drone.yml`): ```bash -helm package . --version 1.2.0 # 生成 mixingx-1.2.0.tgz -# 上传到 kube-node 工具的 /charts 页(agents/edges 新格式门禁) +helm lint release-charts/mixingx-edge-unit +helm template ci-edge release-charts/mixingx-edge-unit ``` -### 部署(Drone CI 链路) +### ArgoCD 部署 -CI 用相对路径 `./mixingx-chart`(submodule 同名),values 覆盖用 `values-105.yaml`: - -```bash -helm upgrade --install production ./mixingx-chart \ - -f mixingx-chart/values-105.yaml \ - --set tag=<镜像tag> \ - --kube-context ctx-105 --namespace mixingx --create-namespace -``` - -### 验证渲染 - -```bash -helm lint . -helm template test . | grep -E "^kind:" | sort | uniq -c -# 默认:23 Service / 16 Deployment / 7 StatefulSet / 5 Secret / 5 ConfigMap / 2 Ingress + SA/Role/RoleBinding -``` +`mixingx-deploy` 的 ApplicationSet 按 unit chart 逐个发布,每个 edge/agent 一个独立 Helm release。详见 `mixingx-deploy/`。 ## 关联文档 -部署链路、kube-node 工具、tier 设计详见 hub 仓库: - - hub [AGENTS.md](https://gitee.com/mixing-tech/mixingx.hub) — 全项目指南 +- `mixingx-deploy/` — ArgoCD Application + 环境 values - `docs/superpowers/specs/2026-07-01-node-tier-affinity-design.md` — 三层调度设计 -- `docs/superpowers/specs/2026-07-01-node-tier-affinity-playbook.md` — 操作手册(流程图+场景速查) diff --git a/templates/_backend.tpl b/templates/_backend.tpl deleted file mode 100644 index c8939bc..0000000 --- a/templates/_backend.tpl +++ /dev/null @@ -1,177 +0,0 @@ -{{/* -公共模板:后端 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) - description - 中文展示名(可选,写为 mixingx.io/description annotation) - 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 }} - {{- if .nodeName }} - nodeName: {{ .nodeName }} - {{- else if .pointAffinity }} - {{ include "mixingx.pointAffinity" (dict "affinity" .pointAffinity "root" .root) }} - {{- else }} - {{ include "mixingx.tierAffinity" (dict "role" .role "root" .root) }} - {{- 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 - env: - # 时区(部署地域覆盖,优先级 > 镜像内 /etc/localtime) - - name: TZ - value: "{{ $root.Values.timezone | default "Asia/Shanghai" }}" - {{- if .rbac }} - - name: POD_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - {{- end }} - livenessProbe: - httpGet: - path: /health - port: http - scheme: HTTP - initialDelaySeconds: 120 - periodSeconds: 30 - timeoutSeconds: 15 - failureThreshold: 12 # 120 + 30×12 = 480s 才杀,容忍 .NET 冷启动连库 - readinessProbe: - httpGet: - path: /alive - port: http - scheme: HTTP - initialDelaySeconds: 60 - periodSeconds: 30 - timeoutSeconds: 10 - failureThreshold: 8 # 60 + 30×8 = 300s 才标 NotReady - ---- -# 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 }} - {{- if and .role (ne .role "gateway") .description }} - annotations: - mixingx.io/description: {{ .description | quote }} - {{- 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 }}" - {{- if .phaseType }} - AGENT_PHASE_TYPE: "{{ .phaseType }}" - {{- end }} - {{- else if hasPrefix "edge" .name }} - EDGE_SERVICE_ID: "{{ .serviceId }}" - {{- else if hasPrefix "sso" .name }} - SSO_SERVICE_ID: "{{ .serviceId }}" - {{- else if hasPrefix "ultra" .name }} - ULTRA_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 -}} diff --git a/templates/_frontend.tpl b/templates/_frontend.tpl deleted file mode 100644 index 97e6ac3..0000000 --- a/templates/_frontend.tpl +++ /dev/null @@ -1,93 +0,0 @@ -{{/* -公共模板:前端 Deployment + Service -可选 podAffinity(四胞胎用:前端和后端同节点) - -参数: - name - 服务名(agent-web-0 / sso-web ...) - image - 镜像名 - port - 端口(默认 80) - basePath - vite base path - affinity - 要亲和的目标服务名(如 "agent-0"),空则不配亲和 - root - $ (root context) -*/}} -{{- define "mixingx.frontend" -}} -{{- $root := .root -}} -{{- $port := .port | default 80 -}} ---- -# 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: 1 - selector: - matchLabels: - app.kubernetes.io/component: {{ .name }} - template: - metadata: - labels: - app.kubernetes.io/component: {{ .name }} - spec: - {{- if .nodeName }} - nodeName: {{ .nodeName }} - {{- else if .affinity }} - # 四胞胎:前端必须和后端同节点(podAffinity + 点位/tier nodeAffinity 合并到同一 affinity 块) - affinity: - podAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - - labelSelector: - matchLabels: - app.kubernetes.io/component: {{ .affinity }} - topologyKey: kubernetes.io/hostname - {{- if .pointAffinity }} - {{ include "mixingx.pointNodeAffinity" (dict "affinity" .pointAffinity "root" $root) }} - {{- else if and $root.Values.tier $root.Values.tier.enabled }} - {{ include "mixingx.tierNodeAffinity" (dict "role" .tierRole "root" $root) }} - {{- end }} - {{- else if .pointAffinity }} - {{ include "mixingx.pointAffinity" (dict "affinity" .pointAffinity "root" $root) }} - {{- else if and $root.Values.tier $root.Values.tier.enabled }} - {{ include "mixingx.tierAffinity" (dict "role" .tierRole "root" $root) }} - {{- end }} - containers: - - name: {{ .name }} - image: {{ $root.Values.registry }}/{{ .image }}:{{ $root.Values.tag | default "latest" }} - imagePullPolicy: IfNotPresent - ports: - - name: http - containerPort: {{ $port }} - protocol: TCP - env: - # 时区(部署地域覆盖,优先级 > 镜像内 /etc/localtime) - - name: TZ - value: "{{ $root.Values.timezone | default "Asia/Shanghai" }}" - - name: VITE_BASE_PATH - value: "{{ .basePath }}" - - name: PORT - value: "{{ $port }}" - ---- -# Service: {{ .name }} -apiVersion: v1 -kind: Service -metadata: - name: {{ .name }}-service - labels: - app.kubernetes.io/name: mixingx - app.kubernetes.io/component: {{ .name }} - mixingx.io/role: web - mixingx.io/node-id: {{ .name }} -spec: - selector: - app.kubernetes.io/component: {{ .name }} - ports: - - name: http - port: {{ $port }} - targetPort: http - protocol: TCP -{{- end -}} diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl deleted file mode 100644 index cb45bab..0000000 --- a/templates/_helpers.tpl +++ /dev/null @@ -1,30 +0,0 @@ -{{/* -完整镜像名: registry/image:tag -用法: {{ include "mixingx.image" (dict "image" .image "Values" $.Values) }} -或: {{ include "mixingx.image" . }}(range 内,. 有 image 字段,但需传 Values) -*/}} -{{- define "mixingx.image" -}} -{{ required "registry is required" .Values.registry }}/{{ required "image is required" .image }}:{{ .Values.tag | default "latest" }} -{{- end -}} - -{{/* -标准标签(所有资源共用) -用法: {{ include "mixingx.labels" (dict "name" "sso" "Release" $.Release) }} -*/}} -{{- define "mixingx.labels" -}} -app.kubernetes.io/name: mixingx -app.kubernetes.io/instance: {{ .Release.Name }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -app.kubernetes.io/component: {{ .name }} -{{- end -}} - -{{/* -Service 的 mixingx.io 标签(gateway 服务发现用) -只在 role 不为空且不为 "gateway" 时打 -*/}} -{{- define "mixingx.discoveryLabels" -}} -{{- if and .role (ne .role "gateway") }} -mixingx.io/role: {{ .role }} -mixingx.io/node-id: {{ .name }} -{{- end }} -{{- end -}} diff --git a/templates/_point-affinity.tpl b/templates/_point-affinity.tpl deleted file mode 100644 index 394a939..0000000 --- a/templates/_point-affinity.tpl +++ /dev/null @@ -1,81 +0,0 @@ -{{/* -渲染点位级原生 nodeAffinity — 完整 affinity 块。 -三层优先级的中层:点位配了 nodeAffinity 时覆盖全局 tier(被 nodeName 覆盖)。 - -参数: - affinity - Point 对象的 nodeAffinity 字段 {required?: [...], preferred?: [...]} - root - $ (root context) -*/}} -{{- define "mixingx.pointAffinity" -}} -{{- $aff := .affinity -}} - affinity: - nodeAffinity: - {{- with $aff.required }} - requiredDuringSchedulingIgnoredDuringExecution: - nodeSelectorTerms: - {{- range . }} - - matchExpressions: - - key: {{ .key }} - operator: {{ .operator }} - {{- if .values }} - values: - {{- range .values }} - - {{ . | quote }} - {{- end }} - {{- end }} - {{- end }} - {{- end }} - {{- with $aff.preferred }} - preferredDuringSchedulingIgnoredDuringExecution: - {{- range . }} - - weight: {{ .weight }} - preference: - matchExpressions: - - key: {{ .key }} - operator: {{ .operator }} - {{- if .values }} - values: - {{- range .values }} - - {{ . | quote }} - {{- end }} - {{- end }} - {{- end }} - {{- end }} -{{- end -}} - -{{/* 只渲染 nodeAffinity 子块(供 frontend/postgres 合并 podAffinity 用)*/}} -{{- define "mixingx.pointNodeAffinity" -}} -{{- $aff := .affinity -}} - nodeAffinity: - {{- with $aff.required }} - requiredDuringSchedulingIgnoredDuringExecution: - nodeSelectorTerms: - {{- range . }} - - matchExpressions: - - key: {{ .key }} - operator: {{ .operator }} - {{- if .values }} - values: - {{- range .values }} - - {{ . | quote }} - {{- end }} - {{- end }} - {{- end }} - {{- end }} - {{- with $aff.preferred }} - preferredDuringSchedulingIgnoredDuringExecution: - {{- range . }} - - weight: {{ .weight }} - preference: - matchExpressions: - - key: {{ .key }} - operator: {{ .operator }} - {{- if .values }} - values: - {{- range .values }} - - {{ . | quote }} - {{- end }} - {{- end }} - {{- end }} - {{- end }} -{{- end -}} diff --git a/templates/_postgres.tpl b/templates/_postgres.tpl deleted file mode 100644 index 763104e..0000000 --- a/templates/_postgres.tpl +++ /dev/null @@ -1,102 +0,0 @@ -{{/* -公共模板:生成独立 postgres StatefulSet + Service + PVC -每个有 DB 的服务(agent/edge/sso/ultra)各自一个 - -参数: - name - 服务名(agent-0 / sso ...) - database - 数据库名(agent-db-0 / sso-db) - pgStorage - PVC 容量(默认 5Gi) - affinity - 是否需要和后端同节点(四胞胎用 true) - root - $ (root context) -*/}} -{{- define "mixingx.postgres" -}} -{{- $root := .root -}} ---- -# StatefulSet: {{ .name }}-postgres -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 - spec: - accessModes: ["ReadWriteOnce"] - storageClassName: local-path - resources: - requests: - storage: {{ .pgStorage | default "5Gi" }} - template: - metadata: - labels: - app.kubernetes.io/component: {{ .name }}-postgres - spec: - {{- if .nodeName }} - nodeName: {{ .nodeName }} - {{- else if .affinity }} - # 四胞胎:postgres 必须和后端 Pod 同节点(podAffinity + 点位/tier nodeAffinity 合并到同一 affinity 块) - affinity: - podAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - - labelSelector: - matchLabels: - app.kubernetes.io/component: {{ .name }} - topologyKey: kubernetes.io/hostname - {{- if .pointAffinity }} - {{ include "mixingx.pointNodeAffinity" (dict "affinity" .pointAffinity "root" $root) }} - {{- else if and $root.Values.tier $root.Values.tier.enabled }} - {{ include "mixingx.tierNodeAffinity" (dict "role" .tierRole "root" $root) }} - {{- end }} - {{- else if .pointAffinity }} - {{ include "mixingx.pointAffinity" (dict "affinity" .pointAffinity "root" $root) }} - {{- else if and $root.Values.tier $root.Values.tier.enabled }} - {{ include "mixingx.tierAffinity" (dict "role" .tierRole "root" $root) }} - {{- end }} - containers: - - name: postgres - image: docker.io/library/postgres:17 - imagePullPolicy: IfNotPresent - env: - - name: POSTGRES_PASSWORD - value: "{{ $root.Values.sharedInfra.postgres.password }}" - - name: POSTGRES_DB - value: "{{ .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 - ---- -# Service: {{ .name }}-postgres-service -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: {{ $root.Values.sharedInfra.postgres.port }} - targetPort: tcp - protocol: TCP -{{- end -}} diff --git a/templates/_tier-affinity.tpl b/templates/_tier-affinity.tpl deleted file mode 100644 index 30b1c0e..0000000 --- a/templates/_tier-affinity.tpl +++ /dev/null @@ -1,80 +0,0 @@ -{{/* -渲染全局 tier 档位调度 nodeAffinity — 完整 affinity 块(无现成 affinity 的模板用)。 -三层优先级的最底层(点位 nodeName > 点位 nodeAffinity > 全局 tier)。 - -参数: - role - 服务角色(gateway/sso/ultra/agent/edge/audit/sharedDatastores) - root - $ (root context) -*/}} -{{- define "mixingx.tierAffinity" -}} -{{- $root := .root -}} -{{- $cfg := $root.Values.tier -}} -{{- if and $cfg $cfg.enabled -}} -{{- $svc := index $cfg.services .role -}} -{{- if $svc -}} -{{- $label := $cfg.nodeLabel | default "mixingx.io/tier" -}} -{{- if eq $svc.mode "required" }} - affinity: - nodeAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - nodeSelectorTerms: - - matchExpressions: - - key: {{ $label }} - operator: In - values: - {{- range $svc.tiers }} - - {{ . | quote }} - {{- end }} -{{- else if eq $svc.mode "preferred" }} - affinity: - nodeAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - {{- range $svc.tiers }} - - weight: 100 - preference: - matchExpressions: - - key: {{ $label }} - operator: In - values: - - {{ . | quote }} - {{- end }} -{{- end }} -{{- end }} -{{- end }} -{{- end -}} - -{{/* 只渲染 nodeAffinity 子块(供 frontend/postgres 合并 podAffinity 用)*/}} -{{- define "mixingx.tierNodeAffinity" -}} -{{- $root := .root -}} -{{- $cfg := $root.Values.tier -}} -{{- if and $cfg $cfg.enabled -}} -{{- $svc := index $cfg.services .role -}} -{{- if $svc -}} -{{- $label := $cfg.nodeLabel | default "mixingx.io/tier" -}} -{{- if eq $svc.mode "required" }} - nodeAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - nodeSelectorTerms: - - matchExpressions: - - key: {{ $label }} - operator: In - values: - {{- range $svc.tiers }} - - {{ . | quote }} - {{- end }} -{{- else if eq $svc.mode "preferred" }} - nodeAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - {{- range $svc.tiers }} - - weight: 100 - preference: - matchExpressions: - - key: {{ $label }} - operator: In - values: - - {{ . | quote }} - {{- end }} -{{- end }} -{{- end }} -{{- end }} -{{- end -}} diff --git a/templates/app-ingress.yaml b/templates/app-ingress.yaml deleted file mode 100644 index 927d50d..0000000 --- a/templates/app-ingress.yaml +++ /dev/null @@ -1,26 +0,0 @@ -{{/* -业务 Ingress — 所有流量 → gateway-service -浏览器访问 app.mixingx.local → Traefik → gateway → 各后端/前端 -*/}} -{{- if .Values.ingress.enabled }} ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: app-ingress - annotations: - traefik.ingress.kubernetes.io/router.entrypoints: web -spec: - ingressClassName: traefik - rules: - - host: {{ .Values.ingress.domain }} - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: {{ .Values.ingress.gatewayService }} - port: - number: {{ .Values.ingress.gatewayPort }} -{{- end }} diff --git a/templates/audit.yaml b/templates/audit.yaml deleted file mode 100644 index a635553..0000000 --- a/templates/audit.yaml +++ /dev/null @@ -1,66 +0,0 @@ -{{- if .Values.audit.enabled }} -{{- $root := $ }} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: audit-deployment - labels: - app.kubernetes.io/name: mixingx - app.kubernetes.io/component: audit -spec: - replicas: {{ .Values.audit.replicas | default 1 }} - selector: - matchLabels: - app.kubernetes.io/component: audit - template: - metadata: - labels: - app.kubernetes.io/component: audit - spec: - {{ include "mixingx.tierAffinity" (dict "role" "audit" "root" $) }} - containers: - - name: audit - image: "{{ .Values.registry }}/{{ .Values.audit.image }}:{{ .Values.tag | default "latest" }}" - imagePullPolicy: IfNotPresent - ports: - - name: http - containerPort: {{ .Values.audit.port }} - protocol: TCP - 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" - - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: "{{ .Values.sharedInfra.otlp.endpoint }}" - - name: OTEL_SERVICE_NAME - value: "audit" ---- -apiVersion: v1 -kind: Service -metadata: - name: audit-service - labels: - app.kubernetes.io/name: mixingx - app.kubernetes.io/component: audit - mixingx.io/role: audit - mixingx.io/node-id: audit -spec: - selector: - app.kubernetes.io/component: audit - ports: - - name: http - port: {{ .Values.audit.port }} - targetPort: http - protocol: TCP -{{- end }} diff --git a/templates/backend-gateway.yaml b/templates/backend-gateway.yaml deleted file mode 100644 index aad0250..0000000 --- a/templates/backend-gateway.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "mixingx.backend" (dict "name" "gateway" "image" "gateway" "role" "gateway" "replicas" 2 "rbac" true "root" $) }} diff --git a/templates/dashboard.yaml b/templates/dashboard.yaml deleted file mode 100644 index 54146a6..0000000 --- a/templates/dashboard.yaml +++ /dev/null @@ -1,67 +0,0 @@ -{{/* -Aspire Dashboard — OTLP 遥测数据接收端 -所有后端的 OTEL_EXPORTER_OTLP_ENDPOINT 指向这里的 :18889 -也是可视化日志/追踪/指标的 Web 界面(:18888) -*/}} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: k8s-dashboard-deployment - labels: - app.kubernetes.io/name: mixingx - app.kubernetes.io/component: k8s-dashboard -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/component: k8s-dashboard - template: - metadata: - labels: - app.kubernetes.io/component: k8s-dashboard - spec: - containers: - - name: k8s-dashboard - image: mcr.microsoft.com/dotnet/nightly/aspire-dashboard:latest - imagePullPolicy: IfNotPresent - ports: - - name: http - containerPort: 18888 - protocol: TCP - - name: otlp-grpc - containerPort: 18889 - protocol: TCP - - name: otlp-http - containerPort: 18890 - protocol: TCP - # Dashboard 无状态,数据在内存(重启清空,不影响业务) - resources: - requests: - memory: 256Mi - limits: - memory: 512Mi ---- -apiVersion: v1 -kind: Service -metadata: - name: k8s-dashboard-service - labels: - app.kubernetes.io/name: mixingx - app.kubernetes.io/component: k8s-dashboard -spec: - selector: - app.kubernetes.io/component: k8s-dashboard - ports: - - name: http - port: 18888 - targetPort: http - protocol: TCP - - name: otlp-grpc - port: 18889 - targetPort: otlp-grpc - protocol: TCP - - name: otlp-http - port: 18890 - targetPort: otlp-http - protocol: TCP diff --git a/templates/gateway-rbac.yaml b/templates/gateway-rbac.yaml deleted file mode 100644 index 83120f6..0000000 --- a/templates/gateway-rbac.yaml +++ /dev/null @@ -1,38 +0,0 @@ -{{/* -Gateway K8s 服务发现 RBAC -gateway 需要读 Service 列表(查 mixingx.io/role 标签)来发现 agent/edge 等 -包括 mqtt-broker Service(查 mixingx.io/role=mqtt-broker,Task 07) -权限只有 Service get/list/watch,不包含 Pod/Secret/ConfigMap -*/}} ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: gateway-sa - labels: - app.kubernetes.io/component: gateway ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: gateway-service-reader - labels: - app.kubernetes.io/component: gateway -rules: - - apiGroups: [""] - resources: ["services"] - verbs: ["get", "list", "watch"] ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - name: gateway-service-reader-binding - labels: - app.kubernetes.io/component: gateway -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: Role - name: gateway-service-reader -subjects: - - kind: ServiceAccount - name: gateway-sa diff --git a/templates/instances.yaml b/templates/instances.yaml deleted file mode 100644 index 2fb0dd3..0000000 --- a/templates/instances.yaml +++ /dev/null @@ -1,54 +0,0 @@ -{{/* - Agent 点位 — 遍历 .Values.agents 数组,每个元素生成完整的三件套 - 生成: 后端 Deployment/Service/ConfigMap/Secret + 前端 Deployment/Service + 独立 Postgres StatefulSet/Service/PVC - 三者通过 podAffinity 强制同节点 - 点位元素可为字符串(老 "0")或对象(新 {site, nodeName?, nodeAffinity?}) -*/}} -{{- range $raw := .Values.agents }} -{{- $site := "" -}} -{{- $nodeName := "" -}} -{{- $pointAffinity := "" -}} -{{- $phaseType := "" -}} -{{- if kindIs "map" $raw -}} -{{- $site = $raw.site | default "" -}} -{{- $nodeName = $raw.nodeName | default "" -}} -{{- $pointAffinity = $raw.nodeAffinity | default "" -}} -{{- $phaseType = $raw.phaseType | default "" -}} -{{- else -}} -{{- $site = $raw | toString -}} -{{- end -}} -{{- $instName := printf "agent-%s" $site }} -{{- $webName := printf "agent-web-%s" $site }} -{{- $dbName := printf "agent-db-%s" $site }} -{{- $basePath := printf "/agent-%s" $site }} -{{- $description := printf "Agent 实例 %s" $site }} -# ═══ 实例: {{ $instName }} ({{ $description }}) ═══ -{{ include "mixingx.backend" (dict "name" $instName "image" "agent" "role" "agent" "serviceId" $instName "phaseType" $phaseType "database" $dbName "description" $description "nodeName" $nodeName "pointAffinity" $pointAffinity "root" $) }} -{{ include "mixingx.frontend" (dict "name" $webName "image" "agent-web" "basePath" $basePath "affinity" $instName "nodeName" $nodeName "pointAffinity" $pointAffinity "tierRole" "agent" "root" $) }} -{{ include "mixingx.postgres" (dict "name" $instName "database" $dbName "pgStorage" "5Gi" "affinity" true "nodeName" $nodeName "pointAffinity" $pointAffinity "tierRole" "agent" "root" $) }} -{{- end }} - -{{/* - Edge 点位 — 遍历 .Values.edges 数组,逻辑同上 -*/}} -{{- range $raw := .Values.edges }} -{{- $site := "" -}} -{{- $nodeName := "" -}} -{{- $pointAffinity := "" -}} -{{- if kindIs "map" $raw -}} -{{- $site = $raw.site | default "" -}} -{{- $nodeName = $raw.nodeName | default "" -}} -{{- $pointAffinity = $raw.nodeAffinity | default "" -}} -{{- else -}} -{{- $site = $raw | toString -}} -{{- end -}} -{{- $instName := printf "edge-%s" $site }} -{{- $webName := printf "edge-web-%s" $site }} -{{- $dbName := printf "edge-db-%s" $site }} -{{- $basePath := printf "/edge-%s" $site }} -{{- $description := printf "Edge 实例 %s" $site }} -# ═══ 实例: {{ $instName }} ({{ $description }}) ═══ -{{ include "mixingx.backend" (dict "name" $instName "image" "edge" "role" "edge" "serviceId" $instName "database" $dbName "description" $description "nodeName" $nodeName "pointAffinity" $pointAffinity "root" $) }} -{{ include "mixingx.frontend" (dict "name" $webName "image" "edge-web" "basePath" $basePath "affinity" $instName "nodeName" $nodeName "pointAffinity" $pointAffinity "tierRole" "edge" "root" $) }} -{{ include "mixingx.postgres" (dict "name" $instName "database" $dbName "pgStorage" "5Gi" "affinity" true "nodeName" $nodeName "pointAffinity" $pointAffinity "tierRole" "edge" "root" $) }} -{{- end }} diff --git a/templates/mock.yaml b/templates/mock.yaml deleted file mode 100644 index 098765b..0000000 --- a/templates/mock.yaml +++ /dev/null @@ -1,58 +0,0 @@ -{{/* -协议模拟器模板 — 遍历 mocks 列表 -每个生成: Deployment + Service -*/}} -{{- range .Values.mocks }} -{{- $root := $ }} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ .name }}-deployment - labels: - {{- include "mixingx.labels" (dict "name" .name "Release" $root.Release) | nindent 4 }} -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/component: {{ .name }} - template: - metadata: - labels: - app.kubernetes.io/component: {{ .name }} - spec: - containers: - - name: {{ .name }} - image: {{ $root.Values.registry }}/{{ .image }}:{{ $root.Values.tag | default "latest" }} - imagePullPolicy: IfNotPresent - {{- if .scene }} - args: - - "--port" - - "{{ .port }}" - - "--scene" - - "{{ .scene }}" - {{- end }} - ports: - - name: tcp - containerPort: {{ .port }} - protocol: TCP - env: - # 时区(部署地域覆盖) - - name: TZ - value: "{{ $root.Values.timezone | default "Asia/Shanghai" }}" ---- -apiVersion: v1 -kind: Service -metadata: - name: {{ .name }}-service - labels: - {{- include "mixingx.labels" (dict "name" .name "Release" $root.Release) | nindent 4 }} -spec: - selector: - app.kubernetes.io/component: {{ .name }} - ports: - - name: tcp - port: {{ .port }} - targetPort: tcp - protocol: TCP -{{- end }} diff --git a/templates/pgadmin.yaml b/templates/pgadmin.yaml deleted file mode 100644 index 3724cf7..0000000 --- a/templates/pgadmin.yaml +++ /dev/null @@ -1,79 +0,0 @@ -{{/* -pgAdmin — 在 K3s 内,用 ClusterIP 直连所有 postgres Pod -宿主的 pgAdmin(5050)是开发用的,这个是测试环境用的 -*/}} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: pgadmin-deployment - labels: - app.kubernetes.io/name: mixingx - app.kubernetes.io/component: pgadmin -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/component: pgadmin - template: - metadata: - labels: - app.kubernetes.io/component: pgadmin - spec: - containers: - - name: pgadmin - image: dpage/pgadmin4:latest - imagePullPolicy: IfNotPresent - env: - - name: PGADMIN_DEFAULT_EMAIL - value: "admin@example.com" # 用 example.com(.local 是 mDNS 保留 TLD,新版 pgadmin email-validator 拒绝) - - name: PGADMIN_DEFAULT_PASSWORD - value: "Admin12345" - - name: PGADMIN_CONFIG_SERVER_MODE - value: "False" - ports: - - name: http - containerPort: 80 - protocol: TCP - resources: - requests: - memory: 128Mi - limits: - memory: 256Mi ---- -apiVersion: v1 -kind: Service -metadata: - name: pgadmin-service - labels: - app.kubernetes.io/name: mixingx - app.kubernetes.io/component: pgadmin -spec: - selector: - app.kubernetes.io/component: pgadmin - ports: - - name: http - port: 80 - targetPort: http - protocol: TCP ---- -# Ingress:走 pgadmin.mixingx.local 域名(和宿主的 pgAdmin 分开) -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: pgadmin-k8s-ingress - annotations: - traefik.ingress.kubernetes.io/router.entrypoints: web -spec: - ingressClassName: traefik - rules: - - host: pgadmin-k8s.mixingx.local - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: pgadmin-service - port: - number: 80 diff --git a/templates/shared-infra.yaml b/templates/shared-infra.yaml deleted file mode 100644 index 3fac2aa..0000000 --- a/templates/shared-infra.yaml +++ /dev/null @@ -1,90 +0,0 @@ -{{/* -共享数据层:redis + mongo + rabbitmq -所有服务连同一个(StatefulSet + PVC 持久化) -postgres 不在这里 — 每个服务有独立的 postgres(见 _postgres.tpl) -*/}} -{{- range .Values.sharedDatastores }} -{{- $root := $ }} ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: {{ .name }}-statefulset - labels: - app.kubernetes.io/name: mixingx - app.kubernetes.io/component: {{ .name }} -spec: - serviceName: {{ .name }}-service - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/component: {{ .name }} - volumeClaimTemplates: - - metadata: - name: data - spec: - accessModes: ["ReadWriteOnce"] - storageClassName: local-path - resources: - requests: - storage: {{ .storage }} - template: - metadata: - labels: - app.kubernetes.io/component: {{ .name }} - spec: - {{ include "mixingx.tierAffinity" (dict "role" "sharedDatastores" "root" $root) }} - containers: - - name: {{ .name }} - image: {{ .image }} - imagePullPolicy: IfNotPresent - ports: - - name: tcp - containerPort: {{ .port }} - protocol: TCP - {{- if eq .name "redis" }} - command: ["/bin/sh"] - args: - - "-c" - - "redis-server --requirepass {{ $root.Values.sharedInfra.redis.password }} --save 60 1" - {{- end }} - {{- if eq .name "mongo" }} - env: - - name: MONGO_INITDB_ROOT_USERNAME - value: "{{ $root.Values.sharedInfra.mongo.username }}" - - name: MONGO_INITDB_ROOT_PASSWORD - value: "{{ $root.Values.sharedInfra.mongo.password }}" - {{- end }} - {{- if eq .name "messaging" }} - env: - - name: RABBITMQ_DEFAULT_USER - value: "{{ $root.Values.sharedInfra.rabbitmq.username }}" - - name: RABBITMQ_DEFAULT_PASS - value: "{{ $root.Values.sharedInfra.rabbitmq.password }}" - {{- end }} - volumeMounts: - - name: data - mountPath: {{ .mountPath }} ---- -apiVersion: v1 -kind: Service -metadata: - name: {{ .name }}-service - labels: - app.kubernetes.io/name: mixingx - app.kubernetes.io/component: {{ .name }} -spec: - selector: - app.kubernetes.io/component: {{ .name }} - ports: - - name: tcp - port: {{ .port }} - targetPort: tcp - protocol: TCP - {{- if eq .name "messaging" }} - - name: management - port: 15672 - targetPort: 15672 - protocol: TCP - {{- end }} -{{- end }} diff --git a/templates/standalones.yaml b/templates/standalones.yaml deleted file mode 100644 index daed1f7..0000000 --- a/templates/standalones.yaml +++ /dev/null @@ -1,18 +0,0 @@ -{{/* -独立实例(sso/ultra)— 遍历 values.standalones 数组 -每个实例生成:后端 Deployment + 前端 Deployment + 独立 postgres StatefulSet(无亲和,多副本) - -与 instances 的差异:无 podAffinity、replicas 可 >1、pgStorage 量级更大。 -*/}} -{{- range $inst := .Values.standalones }} -{{- $root := $ }} -# ═══ 实例: {{ $inst.name }} ({{ $inst.description }}) ═══ -# 1. 后端(多副本) -{{ include "mixingx.backend" (dict "name" $inst.name "image" $inst.image "role" $inst.role "replicas" $inst.replicas "serviceId" $inst.serviceId "database" $inst.database "description" $inst.description "root" $root) }} - -# 2. 前端(无 podAffinity,走 tier nodeAffinity) -{{ include "mixingx.frontend" (dict "name" $inst.webName "image" $inst.webImage "basePath" $inst.webBasePath "tierRole" $inst.role "root" $root) }} - -# 3. 独立 postgres(无 podAffinity,走 tier nodeAffinity) -{{ include "mixingx.postgres" (dict "name" $inst.name "database" $inst.database "pgStorage" $inst.pgStorage "affinity" false "tierRole" $inst.role "root" $root) }} -{{- end }} diff --git a/values-105.yaml b/values-105.yaml deleted file mode 100644 index 03b5066..0000000 --- a/values-105.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# ═══════════════════════════════════════════════════════════════ -# 105 生产环境 values(覆盖 values.yaml 的默认值) -# ═══════════════════════════════════════════════════════════════ - -registry: 192.168.1.105:8888/mixingx - -infra: - postgres: - password: "Admin12345" # 105 实际密码 - redis: - password: "Admin12345" - mongo: - password: "Admin12345" - -tag: latest diff --git a/values.yaml b/values.yaml deleted file mode 100644 index 0ee7f5e..0000000 --- a/values.yaml +++ /dev/null @@ -1,168 +0,0 @@ -# ═══════════════════════════════════════════════════════════════ -# MixingX Helm Chart — values -# 架构:独立 DB + 四胞胎(agent/edge podAffinity) + 共享基础设施 -# ═══════════════════════════════════════════════════════════════ - -# ── 全局 ── -registry: 192.168.1.105:8888/mixingx -tag: latest - -# 时区(部署地域覆盖):中国 Asia/Shanghai,海外按需改如 America/New_York -# 注入所有容器的 TZ env,覆盖镜像内默认时区(镜像内置 Asia/Shanghai 兜底) -timezone: Asia/Shanghai - -# ── 共享基础设施(所有服务连同一个) ── -sharedInfra: - postgres: # postgres 连接参数(每个独立 postgres 共用) - username: postgres - password: "Admin12345" - port: 5432 - redis: - host: redis-service - port: 6379 - password: "Admin12345" - rabbitmq: - host: messaging-service - port: 5672 - username: guest - password: guest - mongo: - host: mongo-service - port: 27017 - username: admin - password: "Admin12345" - database: mixingx_audit - otlp: - endpoint: http://k8s-dashboard-service:18889 - protocol: grpc - -# ═══════════════════════════════════════════════════════════════ -# 类型 A:四胞胎(agent/edge)— 后端+前端+独立DB,podAffinity 同节点 -# 每个实例生成:后端 Deployment + 前端 Deployment + 独立 postgres StatefulSet -# 默认各 1 个,以后按需加(加一行 values + helm upgrade) -# ═══════════════════════════════════════════════════════════════ -# ═══════════════════════════════════════════════════════════════ -# 点位配置 — 只写名字,模板自动推导其余字段 -# 格式: agents/edges 元素可为字符串(老格式 "0")或对象(新格式 {site, nodeAffinity, nodeName}) -# 生成规则: -# 后端: {role}-{site} 如 agent-0, agent-beijing -# 前端: {role}-web-{site} 如 agent-web-0, agent-web-beijing -# 数据库: {role}-db-{site} 如 agent-db-0, agent-db-beijing -# basePath: /{role}-{site} 如 /agent-0, /agent-beijing -# ═══════════════════════════════════════════════════════════════ - -agents: - - "0" - # - beijing - # - shanghai - -edges: - - "0" - # - guangzhou - -# ═══════════════════════════════════════════════════════════════ -# 节点档位调度(可选)— 按硬件能力把服务分配到相应 node -# 前提:给集群节点打 label kubectl label node mixingx.io/tier= -# infra=基础设施级(最强) perf=性能级(中等) edge=边缘级(最弱) -# enabled=false 时完全不渲染调度(默认,向后兼容) -# 点位级覆盖:agents/edges 元素可用对象格式 {site, nodeName?, nodeAffinity?} 覆盖 -# ═══════════════════════════════════════════════════════════════ -tier: - enabled: false - nodeLabel: mixingx.io/tier - services: - gateway: { mode: required, tiers: [infra] } - sso: { mode: required, tiers: [infra] } - ultra: { mode: required, tiers: [infra] } - audit: { mode: required, tiers: [infra] } - sharedDatastores: { mode: required, tiers: [infra] } - agent: { mode: preferred, tiers: [perf, infra] } - edge: { mode: preferred, tiers: [edge, perf, infra] } - -# ═══════════════════════════════════════════════════════════════ -# 类型 B:独立不亲和(sso/ultra)— 后端+前端+独立DB,无亲和,多副本 -# 固定数量,不动态添加 -# ═══════════════════════════════════════════════════════════════ -standalones: - - name: sso - image: sso - role: sso - webName: sso-web - webImage: sso-web - webBasePath: /sso/ - serviceId: sso - database: sso-db - pgStorage: 10Gi - description: "统一登录" - replicas: 2 - affinity: false - - - name: ultra - image: ultra - role: ultra - webName: ultra-web - webImage: ultra-web - webBasePath: /ultra/ - database: ultra-db - pgStorage: 10Gi - description: "Ultra 看板" - replicas: 2 - affinity: false - -# ═══════════════════════════════════════════════════════════════ -# 类型 C/D:无独立 DB 的服务 -# ═══════════════════════════════════════════════════════════════ -gateway: - image: gateway - port: 8080 - replicas: 2 - rbac: true # serviceAccountName: gateway-sa - -audit: - enabled: true - image: audit - port: 5600 - replicas: 2 - -# ── 共享数据层(非 postgres) ── -sharedDatastores: - - name: redis - image: docker.io/library/redis:8.6 - port: 6379 - storage: 2Gi - mountPath: /data - - name: mongo - image: docker.io/library/mongo:8.3 - port: 27017 - storage: 5Gi - mountPath: /data/db - - name: messaging - image: docker.io/library/rabbitmq:4.3-management - port: 5672 - storage: 2Gi - mountPath: /var/lib/rabbitmq - -# ── 协议模拟器(测试环境) ── -mocks: - - name: opcua-peripheral - image: opcua - port: 25006 - scene: /scenes/opcua/peripheral-plc.json - - name: opcua-trimming - image: opcua - port: 25008 - scene: /scenes/opcua/trimming-machine.json - - name: opcua-meter - image: opcua - port: 25010 - scene: /scenes/opcua/meter.json - - name: s7-diecast - image: s7-diecast - port: 11021 - -# ── Ingress ── -ingress: - enabled: true - domain: app.mixingx.local - gatewayService: gateway-service # 所有流量 → gateway,由 gateway 动态路由 - gatewayPort: 8080