commerce · platform 命名空间下的后端微服务

commerce 是运行在 platform 命名空间的一个 Go 后端微服务(镜像 ghcr.io/yldm-tech/commerce,容器以 SERVER_MODE=release 启动),监听 HTTP 8080,启动后向 Consul 注册自己,使用一套独立的数据库凭证(commerce-db-secret)连接专属数据库与 Redis,并签发/刷新 JWT。manifest 未暴露具体业务语义,以下只描述可从清单核实的技术事实。

manifest 中没有该服务的 CLAUDE.md 专属踩坑段,因此本页只覆盖部署、配置与监控三部分。

部署形态

  • Name
    命名空间
    Description
    platform(kustomization 设置 namespace: platformnamePrefix: platform-,生成的资源名为 platform-commerce-*
  • Name
    工作负载
    Description
    Deployment,revisionHistoryLimit: 2,滚动更新策略 maxUnavailable: 0 / maxSurge: 1
  • Name
    镜像与版本
    Description
    ghcr.io/yldm-tech/commerce:2.3.1(tag 由 argocd-image-updater 按 semver 写回 kustomization images: 块,不要手动钉版本)
  • Name
    副本数
    Description
    2(kustomization replicas: count: 2,与 HPA 的 minReplicas: 2 一致)
  • Name
    调度
    Description
    nodeSelector: workload=apppriorityClassName: production-high;软反亲和(preferredDuringScheduling,按 app=commercekubernetes.io/hostname 上打散,weight 100)
  • Name
    端口
    Description
    容器 containerPort: 8080(name http
  • Name
    资源
    Description
    requests cpu 50m / memory 64Mi,limits cpu 200m / memory 256Mi
  • Name
    存储
    Description
    无 PVC,配置以只读 ConfigMap 卷挂载(base-config 挂到 /root/configs/basecommerce-configcommerce.yaml 以 subPath 挂到 /root/configs/services/commerce.yaml

Deployment 经 kustomize patch 注入 reloader.stakater.com/auto: "true" 注解,挂载的 ConfigMap/Secret 变更时由 Reloader 触发滚动重启。

配置与依赖

容器以 CONFIG_FILE=configs/services/commerce.yaml 启动,该文件来自 commerce-config ConfigMap,继承 base/production.yaml 并覆盖特定字段:数据库名 ${DB_NAME:yldm_commerce}、Redis db ${REDIS_DB:2}、tracing service_name: yldm-commerce、pubsub 前缀 yldm:commerce(pubsub Redis db ${REDIS_PUBSUB_DB:1}、死信键 yldm:commerce:deadletter)。

配置中还声明了一个外部服务依赖 user:base_url ${USER_SERVICE_BASE_URL:http://prod-user:80/api/v1/internal},鉴权头 X-Service-Tokentimeout 3scache_ttl 60sstale_ttl 300s

数据库与 Redis 凭证经 ExternalSecret commerce-db-secret(ClusterSecretStore vault-backendrefreshInterval: 1h)从 Vault 拉取,注入为环境变量:

环境变量Vault remoteRef.keyproperty
DB_HOST / DB_PORT / DB_NAME / DB_USER / DB_PASSWORDyldm/production/commercedb_host / db_port / db_name / db_user / db_password
REDIS_HOST / REDIS_PORT / REDIS_PASSWORD / REDIS_DB / REDIS_PUBSUB_DByldm/production/commerceredis_host / redis_port / redis_password / redis_db / redis_pubsub_db
JWT_SECRET / JWT_EXPIRES_IN / JWT_REFRESH_EXPIRES_INyldm/production/commercejwt_secret / jwt_expires_in / jwt_refresh_expires_in
DB_ADMIN_USER / DB_ADMIN_PASSWORDyldm/databaseuser / password

注释说明该服务使用独立的 Secret 实现数据库凭证隔离。Consul 服务注册相关 env 直接写在 Deployment 中:CONSUL_ENABLED=trueCONSUL_ADDR=consul.consul.svc.cluster.local:8500SERVER_PORT=8080SERVER_NAME=commerce

访问与监控

  • Name
    Service
    Description
    ClusterIP(默认类型,未声明 type),port 80targetPort 8080,name http,selector app=commerce;无 Ingress,集群内通过 platform-commerce:80 访问
  • Name
    健康检查
    Description
    livenessProbe GET /health/live(initialDelay 30s、period 10s);readinessProbe GET /health/ready(initialDelay 15s、period 5s、timeout 5s)
  • Name
    ServiceMonitor
    Description
    有,抓取 http 端口 /metricsinterval 30s,并 relabel 出 pod / namespace / service 标签
  • Name
    PrometheusRule
    Description
    有,commerce.rules 组覆盖 Pod 存活(CommercePodDown / CommerceInsufficientPods)、HTTP 5xx 错误率(warning >3% / critical >5%)、P95 延迟(warning >0.5s / critical >1s)、频繁重启、CPU 与内存使用率(>80%)
  • Name
    HPA
    Description
    minReplicas 2 / maxReplicas 5,目标 CPU 利用率 70%、内存 80%;扩容快(stabilization 0s,Percent 100% / Pods 2,每 30s,取 Max),缩容慢(stabilization 300s,Percent 50%,每 60s)
  • Name
    VPA
    Description
    commerce-vpaupdateMode: "Off"(仅推荐不自动改),区间 cpu 25m–500m、memory 32Mi–512Mi
  • Name
    PDB
    Description
    maxUnavailable: 1,selector app=commerce

返回 platform 总览

评论