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

在AWS EKS中用单个公网IP暴露不同端口的两类Pod

AWS EKS 单公网IP暴露多端口Pod的标准实现方式

在AWS EKS中,要通过单个公网IP对外暴露两个分属不同Deployment的TCP端口Pod,标准方案是借助AWS Network Load Balancer(NLB)和AWS Load Balancer Controller,通过配置多端口路由到对应Pod的后端服务。具体操作步骤如下:

1. 确认集群已部署AWS Load Balancer Controller

这是AWS官方提供的用于管理EKS中NLB/ALB的控制器,若集群未部署,需先通过Helm或AWS CDK完成安装。

2. 给两个Deployment的Pod设置唯一标签

为两个Deployment的Pod配置不同的标签,方便后续关联后端服务:

  • Pod A的Deployment标签:app: pod-a
  • Pod B的Deployment标签:app: pod-b

3. 创建两个ClusterIP类型的Service

分别为两个Pod创建ClusterIP Service,用于将流量转发到各自的Deployment:

Pod A的Service配置:

apiVersion: v1
kind: Service
metadata:
  name: service-a
spec:
  type: ClusterIP
  selector:
    app: pod-a
  ports:
    - protocol: TCP
      port: 1500
      targetPort: 1500

Pod B的Service配置:

apiVersion: v1
kind: Service
metadata:
  name: service-b
spec:
  type: ClusterIP
  selector:
    app: pod-b
  ports:
    - protocol: TCP
      port: 2000
      targetPort: 2000

4. 配置TCP端口转发的Ingress与ConfigMap

通过Ingress资源指定创建单IP的NLB,并利用ConfigMap映射公网端口到对应ClusterIP Service:

Ingress资源配置:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: multi-port-tcp-ingress
  annotations:
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/load-balancer-type: nlb
    alb.ingress.kubernetes.io/target-type: ip
    # 启用NLB单公网IP模式
    alb.ingress.kubernetes.io/aws-load-balancer-single-instance: "true"
spec:
  ingressClassName: alb

TCP端口映射ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: kube-system
data:
  "1500": "default/service-a:1500"
  "2000": "default/service-b:2000"

验证配置

部署完成后,通过kubectl get ingress获取NLB的公网IP,即可通过该IP的1500端口访问Pod A,2000端口访问Pod B。

内容的提问来源于stack exchange,提问作者ascobol

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 08:22:36