kubernets几种端口(port、targetport、contaierport、hostport、nodeport)的区别和关联

1,507 阅读1分钟

1.这两个一般用在应用yaml描述文件中,起到的作用类似于docker -p选项 containerport: 容器需要暴露的端口,service的targetPort会映射到pod里的这个containerPort。 hostport: 容器暴露的端口映射到的物理机的主机端口。

2.这两个一般用在service中,service 的类型为cluster ip时候: port: service中clusterip 对应的端口 targetport: clusterIP作为负载均衡, 后端目标实例(容器)的端口。targetPort对应pod里的containerPort。

3.这一个一般用在service中,service的类型为nodeport: cluster ip 只能集群内部访问(源与目标需要满足两个条件: kube-proxy正常运行,跨主机容器网络通信正常),nodeport会在每个kubelet节点的宿主机开启一个端口,用于应用集群外部访问。 4.hostport和nodeport的区别? (1)hostport是将pod的端口映射到宿主机上。 (2)nodeport是将service的端口映射到集群中的每个宿主机上。

关于端口的总结 快速总结一下哪些端口和标签应该匹配: Service selector 应该和 Pod 的标签匹配; Service 的 targetPort 应该和 Pod 里面容器的 containerPort 匹配; Service 端口可以是任意数字。多个 Service 可以使用同一个端口,因为不同的 Service 分配的 IP 地址不同; Ingress 的 service.port 应该和 Service 的 port 匹配; Service 的名称应该和 Ingress 中 service.name 字段匹配;