user · 平台用户服务

平台域的用户服务,运行在 platform 命名空间,是一个监听 8080 端口、暴露 /health/live/health/ready/metrics 的 HTTP 微服务。

它通过 ExternalSecret 拿到自己独立的 MySQL 与 Redis 凭证(凭证隔离),启动时向 Consul 注册自身(SERVER_NAME=user),并在配置里声明了 GitHub OAuth 与基于 Redis 的 pubsub。这里只描述 manifest 可验证的技术事实,不对业务语义做扩展推断。

部署形态

  • Name
    命名空间
    Description
    platform(kustomization 设 namespace: platformnamePrefix: platform-,生成的 Application 为 platform-user
  • Name
    工作负载
    Description
    Deployment
  • Name
    镜像
    Description
    ghcr.io/yldm-tech/user,kustomization images: 锁定 newTag 2.4.0(覆盖 deployment.yaml 内联的 2.3.1);tag 由 argocd-image-updater 按 semver 写回,不要手动 pin
  • Name
    副本数
    Description
    2(kustomization replicas: count: 2,与 HPA minReplicas 一致)
  • Name
    调度
    Description
    nodeSelector: workload=app;podAntiAffinity 按 kubernetes.io/hostname 软反亲和(preferred,weight 100)打散同 app=user 的副本
  • Name
    优先级
    Description
    priorityClassName production-high(kustomization patch 注入)
  • Name
    端口
    Description
    容器 8080(name http
  • Name
    资源
    Description
    requests cpu 50m / memory 64Mi;limits cpu 200m / memory 256Mi
  • Name
    滚动策略
    Description
    RollingUpdate,maxUnavailable 0 / maxSurge 1
  • Name
    探针
    Description
    liveness GET /health/live(initialDelay 30s,period 10s);readiness GET /health/ready(initialDelay 15s,period 5s,timeout 5s)
  • Name
    存储
    Description
    无 PVC,无状态;仅挂载两个 ConfigMap(base-config/root/configs/baseuser-configuser.yaml/root/configs/services/user.yaml

Pod 通过 ghcr-secret 拉取镜像;deployment 上由 reloader.stakater.com/auto: "true" 注解,ConfigMap/Secret 变更会触发滚动重启。

配置与依赖

服务配置走 CONFIG_FILE=configs/services/user.yaml,由 ConfigMap user-config 提供,继承 base/production.yaml 再覆盖特定字段。关键覆盖项:

配置
database.database${DB_NAME:yldm_user}
redis.db${REDIS_DB:0}
tracing.service_nameyldm-user
pubsub.prefixyldm:user
pubsub.redis.db${REDIS_PUBSUB_DB:1}
pubsub.dead_letter.keyyldm:user:deadletter
oauth.github.redirect_uri${GITHUB_REDIRECT_URI:kubepocket://auth/github/callback}

敏感凭证由 ExternalSecret user-db-secret 从 ClusterSecretStore vault-backend(KV v2)拉取,目标 Secret 同名 user-db-secretrefreshInterval: 1h。多数键来自 yldm/production/user,数据库管理员账号来自共享路径 yldm/database

  • Name
    yldm/production/user
    Description
    db_host / db_port / db_name / db_user / db_password、redis_host / redis_port / redis_password / redis_db / redis_pubsub_db、jwt_secret / jwt_expires_in / jwt_refresh_expires_in
  • Name
    yldm/database
    Description
    DB_ADMIN_USER ← user、DB_ADMIN_PASSWORD ← password

依赖项:MySQL(DB_*,库名默认 yldm_user)、Redis(缓存 db 0 与 pubsub db 1,REDIS_*)、Consul(CONSUL_ENABLED=trueCONSUL_ADDR=consul.consul.svc.cluster.local:8500)。其余环境变量:ENV/ENVIRONMENT=productionSERVER_MODE=releaseSWAGGER_AUTO_GEN=falseSERVER_PORT=8080SERVER_NAME=user。GitHub OAuth 的 client_id / client_secret 在配置里以 ${GITHUB_CLIENT_ID} / ${GITHUB_CLIENT_SECRET} 占位,manifest 未声明其注入来源。

访问与监控

  • Name
    Service
    Description
    ClusterIP(默认类型),名为 userport 80 → targetPort 8080,无 Ingress(仅集群内访问,外部入口由 Consul/上游网关决定,不在本目录)
  • Name
    ServiceMonitor
    Description
    有,30s 抓 http 端口的 /metrics,relabel 出 pod / namespace / service 标签
  • Name
    PrometheusRule
    Description
    有,user.rules 组覆盖:Pod 下线、副本不足、HTTP 5xx 错误率(warning >3% / critical >5%)、P95 延迟(warning >0.5s / critical >1s)、频繁重启、CPU/内存超 80%
  • Name
    HPA
    Description
    min 2 / max 5,目标 CPU 70% 与内存 80%;scaleUp 无稳定窗口(按 100%/2 pods 每 30s 取 Max),scaleDown 稳定窗口 300s(每 60s 最多 50%)
  • Name
    VPA
    Description
    updateMode: Off(仅推荐不自动改),min cpu 25m/mem 32Mi,max cpu 500m/mem 512Mi
  • Name
    PDB
    Description
    maxUnavailable 1(符合本仓库单/多副本约定,不会楔住节点 drain)

返回 platform 服务总览

评论