Kubernetes:当每个 pod 暴露一个端口时,一个节点中有多个 pods
Kubernetes: multiple pods in a node when each pod exposes a port
我一直在关注 Kubernetes 入门指南中的 Hello, World example。
在该示例中,在 Google 容器引擎上创建了一个具有 3 nodes/instances 的集群。
要部署的container
是一个基本的nodejs http服务器,监听8080端口
现在当我运行
kubectl run hello-node --image <image-name> --port 8080
它创建一个 pod
和一个 deployment
,在其中一个节点上部署 pod
。
运行
kubectl scale deployment hello-node --replicas=4
命令将 pods 的数量增加到 4.
但是由于每个pod都暴露了8080端口,会不会在部署两个节点的pod上造成端口冲突?
当我执行 kubernetes get pods
时,我可以看到 4 pods,但是在这种情况下会发生什么行为?
您的 pod 公开的端口与节点上的物理端口之间存在差异。那些需要通过例如 kubernetes service or a loadBalancer as discussed a bit further in the hello-world documentation http://kubernetes.io/docs/hellonode/#allow-external-traffic
链接
在 #kubernetes-users
channel on slack 中得到了一些帮助:
kubectl run ...
中指定的端口是pod
的端口。每个 pod 都有其唯一的 IP 地址。所以,没有端口冲突。
- pods 不会提供流量,除非您将它们公开为
service
。
- 通过 运行
kubectl expose ...
公开 service
在 每个 node
。此端口对于每个服务都必须是唯一的。
- 如果一个节点有多个 pods
kube-proxy
平衡这些 pods 之间的流量。
此外,当我从浏览器访问我的服务时,我能够在所有 4 pods 中看到日志,因此流量来自所有 4 pods.
我一直在关注 Kubernetes 入门指南中的 Hello, World example。
在该示例中,在 Google 容器引擎上创建了一个具有 3 nodes/instances 的集群。
要部署的container
是一个基本的nodejs http服务器,监听8080端口
现在当我运行
kubectl run hello-node --image <image-name> --port 8080
它创建一个 pod
和一个 deployment
,在其中一个节点上部署 pod
。
运行
kubectl scale deployment hello-node --replicas=4
命令将 pods 的数量增加到 4.
但是由于每个pod都暴露了8080端口,会不会在部署两个节点的pod上造成端口冲突?
当我执行 kubernetes get pods
时,我可以看到 4 pods,但是在这种情况下会发生什么行为?
您的 pod 公开的端口与节点上的物理端口之间存在差异。那些需要通过例如 kubernetes service or a loadBalancer as discussed a bit further in the hello-world documentation http://kubernetes.io/docs/hellonode/#allow-external-traffic
链接在 #kubernetes-users
channel on slack 中得到了一些帮助:
kubectl run ...
中指定的端口是pod
的端口。每个 pod 都有其唯一的 IP 地址。所以,没有端口冲突。- pods 不会提供流量,除非您将它们公开为
service
。 - 通过 运行
kubectl expose ...
公开service
在 每个node
。此端口对于每个服务都必须是唯一的。 - 如果一个节点有多个 pods
kube-proxy
平衡这些 pods 之间的流量。
此外,当我从浏览器访问我的服务时,我能够在所有 4 pods 中看到日志,因此流量来自所有 4 pods.