仪表盘
Nantian Gateway 仪表盘是一个随控制面一起部署的 Next.js 管理界面。它提供了用于查看网关状态、路由配置和监控数据面连接的 Web 界面,无需直接使用 kubectl 或 Admin API。
仪表盘连接到控制面的 Admin API 并从中读取配置。它不写入任何内容:它是一个仅供运维人员使用的只读可观测性工具。
Helm Chart 中仪表盘默认启用。以下配置项控制其部署:
dashboard: enabled: true replicas: 1 authSecret: "" authExistingSecret: "" serviceAccount: name: "" annotations: {} image: repository: nantian/dashboard tag: "" pullPolicy: IfNotPresent resources: {} nodeSelector: {} tolerations: [] affinity: {} podAnnotations: {} networkPolicy: enabled: false ingress: enabled: false className: "" hosts: [] tls: []| 配置项 | 默认值 | 说明 |
|---|---|---|
dashboard.enabled | true | 开关仪表盘的 Deployment 和 Service。 |
dashboard.replicas | 1 | 仪表盘 Pod 副本数。由于仪表盘是无状态的,且它查询的 Admin API 运行在控制面上,多副本通常没什么用。 |
dashboard.serviceAccount.name | "" | 自定义 ServiceAccount 名称。为空时,Chart 根据 release 名称自动生成。 |
部署后,仪表盘 Service 在 release 命名空间中监听端口 3000,Service 名称为 nantian-gw-dashboard。
通过端口转发本地访问:
kubectl port-forward -n nantian-gw svc/nantian-gw-dashboard 3000:3000然后在浏览器中打开 http://localhost:3000。
通过 Ingress 集群内访问:
要通过 Ingress 暴露仪表盘,设置 dashboard.ingress.enabled: true 并配置 hosts 和 tls:
dashboard: ingress: enabled: true className: nginx hosts: - dashboard.nantian.example.com tls: - hosts: - dashboard.nantian.example.com secretName: dashboard-tls仪表盘自身不提供 HTTPS:在 Ingress 层终止 TLS。
仪表盘登录页面接受一个 bearer token。该 token 的来源取决于控制面的认证模式。
静态 token 模式(默认)
Section titled “静态 token 模式(默认)”当 controlplane.config.adminAuth.authMode 为 "static"(默认)时,控制面接受单个预配置的 bearer token。通过控制面配置中的 adminAuth.bearerToken 设置。仪表盘将此 token 传递给控制面的 Admin API。
Kubernetes token 模式(生产环境推荐)
Section titled “Kubernetes token 模式(生产环境推荐)”当 controlplane.config.adminAuth.authMode 为 "kubernetes" 时,控制面通过 Kubernetes TokenReview API 验证 token。运维人员可以使用 Kubernetes ServiceAccount token 进行认证。
创建一个 ServiceAccount 并将其绑定到控制面的 ClusterRole:
kubectl create sa dashboard-operator -n nantian-gwkubectl create clusterrolebinding dashboard-operator \ --clusterrole=nantian-gw-controlplane \ --serviceaccount=nantian-gw:dashboard-operator生成 token 并在登录页面输入:
kubectl create token dashboard-operator -n nantian-gw该 token 由控制面通过 Kubernetes TokenReview API 进行验证。控制面 ServiceAccount 需要创建 tokenreviews 的权限(Helm Chart 自动授予)。
Token 具有有限的生命周期(kubectl create token 默认 1 小时)。旧 token 过期后创建新 token 即可。
获取自动生成的 token(未配置 token 时)
Section titled “获取自动生成的 token(未配置 token 时)”如果未设置 authSecret、authExistingSecret 或静态 bearerToken,且 authMode 为 "static" 且未配置 token,仪表盘以只读模式运行,无需认证。这适用于本地开发和防火墙后的端口转发访问。
如果在仪表盘 Helm 配置中设置了 authSecret 或 authExistingSecret,仪表盘将其用于会话认证。Helm Chart 也会自动生成一个名为 <release>-dashboard-auth 的随机 Secret:
kubectl get secret -n nantian-gw nantian-gw-dashboard-auth \ -o jsonpath='{.data.auth-secret}' | base64 -decho仪表盘登录时使用你提供的 bearer token 对控制面 Admin API 进行认证。而数据面 Admin API 使用的是另一个独立的 bearer token(见 数据面配置 → adminAuth)。
由于仪表盘的服务端代理(BFF)会代替你调用数据面 Admin——用于 /v1/summary 和诊断——它需要数据面的 token。如果缺失,数据面诊断将受限,仪表盘会提示:
Traffic and dataplane diagnostics are limited because the current dashboard session cannot access dataplane /v1/summary.
当 Chart 管理数据面 admin token 时,Helm 会自动处理:仪表盘 Deployment 会收到一个 DATAPLANE_BEARER_TOKEN 环境变量,取值自数据面 admin 认证 Secret(<release>-dataplane-admin-auth,key 为 token)。这种情况下无需额外配置。
当数据面 admin 使用内联 token(dataplane.config.adminAuth.bearerToken)而非 Chart 管理的 Secret 时,需要显式设置 DATAPLANE_BEARER_TOKEN——可以通过挂载到仪表盘的自定义 Secret,或让数据面 admin 认证指向一个仪表盘也能引用的 Secret。
| 环境变量 | 来源 | 用途 |
|---|---|---|
DATAPLANE_BEARER_TOKEN | 数据面 admin 认证 Secret | 仪表盘 BFF 代理向数据面 Admin API 认证。 |
CONTROLPLANE_ADMIN_URL | Chart 计算的集群内 URL | 控制面 Admin API 基础 URL。 |
DATAPLANE_ADMIN_URL | Chart 计算的集群内 URL | 数据面 Admin API 基础 URL。 |
仪表盘依赖控制面的 Admin API 可达。Admin API 由控制面的 Deployment 在端口 18081 上提供服务(Service:nantian-gw-controlplane-admin)。如果控制面 Pod 未运行或 Admin API 不健康,仪表盘会显示连接错误。
仪表盘查询的端点见 Admin API 参考。
NetworkPolicy
Section titled “NetworkPolicy”当 dashboard.networkPolicy.enabled 为 true 时,Chart 会创建一个 Kubernetes NetworkPolicy,允许仪表盘 Pod 访问控制面的 Admin API。如果你的集群有额外的网络限制,可以在此基础上自定义。