auth · 平台认证服务

auth 是 platform 类目下的一个微服务,镜像来自 ghcr.io/yldm-tech/auth,对外暴露 HTTP 8080 端口并提供 /health/live/health/ready/metrics 端点。从配置看,它负责 JWT 的签发与刷新(JWT_SECRET / JWT_EXPIRES_IN / JWT_REFRESH_EXPIRES_IN)以及 GitHub OAuth 登录回调(GITHUB_REDIRECT_URIkubepocket://auth/github/callback,指向一个名为 kubepocket 的客户端),数据落在 MySQL,会话与发布订阅走 Redis,并通过 Consul 做服务注册。镜像 tag 由 argocd-image-updater 按 semver 写回 kustomization,不要手动钉版本。

部署形态

  • Name
    命名空间
    Description
    platform(kustomization 设 namespace: platformnamePrefix: platform-,故活动对象名为 platform-auth-*
  • Name
    工作负载
    Description
    Deployment
  • Name
    镜像 / 版本
    Description
    ghcr.io/yldm-tech/auth:2.3.1(kustomization images: 写回目标)
  • Name
    副本数
    Description
    2(kustomization replicas: 与 deployment replicas 均为 2)
  • Name
    滚动策略
    Description
    maxUnavailable: 0maxSurge: 1,更新期间不减少可用副本
  • Name
    调度
    Description
    nodeSelector: workload=apppriorityClassName: production-high;按 app=auth 标签做主机级 podAntiAffinity(preferred,topologyKey kubernetes.io/hostname
  • Name
    端口
    Description
    容器 8080,命名 http
  • Name
    资源
    Description
    requests cpu 50m / memory 64Mi,limits cpu 200m / memory 256Mi
  • Name
    健康检查
    Description
    liveness GET /health/live(initialDelay 30s,period 10s);readiness GET /health/ready(initialDelay 15s,period 5s,timeout 5s)
  • Name
    存储
    Description
    无 PVC,配置以 ConfigMap 卷只读挂载

配置与依赖

容器以 CONFIG_FILE=configs/services/platform/auth.yaml 读取配置,该文件来自 auth-config ConfigMap,挂载到 /root/configs/services/platform/auth.yaml(subPath);另有一个集群共享的 base-config ConfigMap 只读挂载到 /root/configs/baseauth.yaml 里 server / database / redis / jwt / oauth 各段的敏感值都用 ${VAR} 占位,由环境变量在运行时注入。kustomization 通过 reloader.stakater.com/auto: "true" 注解让 reloader 在 ConfigMap/Secret 变更时自动滚动 Deployment。

运行环境固定为生产:ENV / ENVIRONMENTproductionSERVER_MODE=releaseSWAGGER_AUTO_GEN=falseSERVER_PORT=8080SERVER_NAME=auth。服务注册开启 Consul:CONSUL_ENABLED=trueCONSUL_ADDR=consul.consul.svc.cluster.local:8500

所有密钥来自 ExternalSecret auth-db-secret(ClusterSecretStore vault-backend,刷新间隔 1h),合成同名 Secret 后被 deployment 以 secretKeyRef 注入:

来源 Vault 路径 (remoteRef.key)注入的键
yldm/production/authdb_host/port/name/user/password、redis_host/port/password/db/pubsub_db、jwt_secret/expires_in/refresh_expires_in
yldm/databaseDB_ADMIN_USER、DB_ADMIN_PASSWORD(共享数据库管理员凭据)
github/appGITHUB_CLIENT_ID、GITHUB_CLIENT_SECRET

依赖小结:MySQL(连接池 max_open_conns 50 / max_idle_conns 10 / conn_max_lifetime 1h)、Redis(含独立的 pub/sub DB)、Consul 服务发现,以及 GitHub OAuth App。

访问与监控

  • Name
    Service
    Description
    ClusterIP(默认类型),名 authport 80 → targetPort 8080,命名 http,无 Ingress
  • Name
    ServiceMonitor
    Description
    有,按 app=auth 选择,抓 http 端口 /metrics,间隔 30s,限定 platform 命名空间
  • Name
    HPA
    Description
    auth-hpa,min 2 / max 10;CPU 目标 70%、内存目标 80%;scaleDown 稳定窗口 300s(每 60s 至多 10%),scaleUp 窗口 0s(每 15s 100% 或 4 个 Pod,取大)
  • Name
    VPA
    Description
    auth-vpaupdateMode: Off(仅推荐不自动改),区间 cpu 25m–500m、memory 32Mi–512Mi
  • Name
    PDB
    Description
    auth-pdbmaxUnavailable: 1

PrometheusRule auth-alerts(组 auth.rules)定义了 5 条告警:AuthHighErrorRate(5xx 占比 > 5%,critical)、AuthHighLatency(p95 > 1s,warning)、AuthPodNotReady(Pod 未就绪超 5 分钟,warning)、AuthHighMemoryUsage(内存用量 > limit 90%,warning)、AuthHighAuthFailureRate(auth_login_failures_total 速率 > 10/s,warning)。

返回 platform 总览

评论