Difference between targetPort and port in Kubernetes Service definition

前端 未结 7 1394
别跟我提以往
别跟我提以往 2020-12-02 04:56

A Kubernetes Service can have a targetPort and port in the service definition:

kind: Servi         


        
7条回答
  •  被撕碎了的回忆
    2020-12-02 05:27

    It helps me to think of things from the perspective of the service.

    • nodePort: The port on the node where external traffic will come in on
    • port: The port of this service
    • targetPort The target port on the pod(s) to forward traffic to

    Traffic comes in on nodePort, forwards to port on the service which then routes to targetPort on the pod(s).

    It's worth emphasizing more that nodePort is for external traffic. Other pods in the cluster that may need to access the service will just use port, not nodePort as it's internal only access to the service.

    Also worth noting that if targetPort is not set, it will default to the same value as port. E.g. 80:80 for service port 80 targeting container port 80.

提交回复
热议问题