Difference between targetPort and port in Kubernetes Service definition

前端 未结 7 1393
别跟我提以往
别跟我提以往 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:30

    This answer is to reference Kubernetes' documentation in addition to the other answers:

    https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/:

    targetPort: is the port the container accepts traffic on,

    port: is the abstracted Service port, which can be any port other pods use to access the Service

    https://kubernetes.io/docs/concepts/services-networking/service/:

    Port definitions in Pods have names, and you can reference these names in the targetPort attribute of a Service. This works even if there is a mixture of Pods in the Service using a single configured name, with the same network protocol available via different port numbers.

提交回复
热议问题