大道至简,知易行难
广阔天地,大有作为

Kubernetes中的几个port

Kubernetes中有几个port容易混淆。

一、Deployment的containerPort

首先是最常见containerPort,以官网文档https://kubernetes.io/docs/concepts/services-networking/connect-applications-service为例:

官网的文档让我们感觉需要使用containerPort来指定暴露的端口,但实际上根据官网https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#container-v1-core中的说明:

List of ports to expose from the container. Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default “0.0.0.0” address inside a container will be accessible from the network. Cannot be updated.

因此,containerPort与Dockerfile的EXPOSE指令都是文档性的。即使不在Kubernetes的Deployment配置中通过containerPort配置端口,我们仍然可以使用集群内的Pod IP访问到容器内绑定到0.0.0.0的端口。

二、Service的port和targetPort

When you use port and targetPort, it will forward service:port to container:targetPort.

Kubernetes中Service的port和targetPort

Kubernetes中Service的port和targetPort

参考文档:
1、https://medium.com/faun/should-i-configure-the-ports-in-kubernetes-deployment-c6b3817e495
2、https://stackoverflow.com/questions/57556606/what-is-the-relationship-between-expose-in-the-dockerfile-and-targetport-in-the

转载时请保留出处,违法转载追究到底:进城务工人员小梅 » Kubernetes中的几个port

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址