【问题标题】:Kubernetes cluster, two containers(different pods) are running on same portKubernetes集群,两个容器(不同的pod)在同一个端口上运行
【发布时间】:2018-01-17 03:09:16
【问题描述】:

我可以在一个 Kubernetes 集群中创建两个容器在相同端口上运行的 pod 吗?考虑到这将为两者创建单独的服务。

类似这样的:

-- 部署1

kind: Deployment
spec:
  containers:
  - name: <name>
    image: <image>
    imagePullPolicy: Always
    ports:
    - containerPort: 8080

-- 服务1

kind: Service
spec:
    type: LoadBalancer
ports:
  - port: 8081
    targetPort: 8080

-- 部署2

kind: Deployment
spec:
  containers:
  - name: <name>
    image: <image>
    imagePullPolicy: Always
    ports:
    - containerPort: 8080

-- 服务 2

kind: Service
spec:
    type: LoadBalancer
ports:
  - port: 8082
    targetPort: 8080

但这种方法行不通。

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    当然可以。每个POD(这是 k8s 中的基本工作负载单元)在网络方面都与其他单元隔离(只要您不弄乱高级网络选项),因此您可以拥有任意数量的 pod 来绑定同一个端口。但是,在同一个 POD 中不能有两个 containers 绑定同一个端口。

    【讨论】:

      【解决方案2】:

      是的,它们是不同 pod 中的不同容器,因此它们之间不应该有任何冲突。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-07-09
        • 2019-01-21
        • 2020-03-01
        • 2015-02-02
        • 1970-01-01
        • 1970-01-01
        • 2020-10-25
        相关资源
        最近更新 更多