假设我们有两个不同的 Docker 镜像,它们都暴露相同的端口(例如 80)。
现在我们想在 Kubernetes 集群中创建一个多容器 Pod,其中包含从这些镜像创建的容器。
有没有办法在不更改图像的情况下设置此类配置?如何在 Pod 级别映射端口?
最佳答案
Kubernetes Pod 内的容器共享不同的 Linux 命名空间,例如网络、pid 或文件系统。 From the docs
Each Pod is assigned a unique IP address. Every container in a Pod shares the network namespace, including the IP address and network ports. Containers inside a Pod can communicate with one another using localhost
因此,就像您不能让两个进程在计算机上的同一端口上监听一样,您也不能让两个共享网络命名空间的容器在同一端口上监听。
关于kubernetes - 在 Pod 级别映射端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48212778/