You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在K8s集群中为Spring Boot的sidecar容器pghero配置非8080端口

在K8s中为Sidecar模式的PgHero配置自定义端口

完全可行,目前PgHero支持通过环境变量PORT指定监听端口,无需使用旧的pghero config:set命令(该命令仅适用于非容器化部署场景)。

具体实现方式

在K8s Deployment的PgHero Sidecar容器配置中,添加PORT环境变量即可修改端口:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: spring-app-pghero
spec:
  template:
    spec:
      containers:
        # Spring Boot主应用容器
        - name: spring-app
          image: your-spring-image:latest
          ports:
            - containerPort: 8080
          # 主应用其他配置

        # PgHero Sidecar容器
        - name: pghero
          image: ankane/pghero:latest
          ports:
            - containerPort: 3030
          env:
            - name: PORT
              value: "3030" # 自定义PgHero监听端口
            - name: DATABASE_URL
              value: "postgres://<user>:<password>@<db-host>:5432/<db-name>" # 数据库连接信息
          # PgHero其他配置

补充说明

  • 如果需要外部访问PgHero,需在对应Service中配置端口映射,将3030端口暴露出去。
  • PgHero官方容器镜像原生支持PORT环境变量配置,这是容器化部署的标准配置方式。

内容的提问来源于stack exchange,提问作者Michael Wälischmiller

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 23:10:18