1

According to https://kubernetes.io/docs/api-reference/v1.8/#serviceport-v1-core , a ServicePort's port (integer) is "The port that will be exposed by this service.", but given that it doesn't specify the port on which a backend pod will listen (those are targetPort and can even be names to be defined by each backend pod) and it doesn't really specify the port to which a frontend pod should connect (those are nodePort or auto-assigned), I'm confused as to what it does specify.

Are load balancers (ingresses?) required to expose the port as identified in a service, or can they map it as well?

The examples at https://kubernetes.io/docs/concepts/services-networking/service/ don't always include names for the ports even though the spec says that "All ports within a ServiceSpec must have unique names." -- this leads me to assume that a stringified port is also the default name. Is that right?

The docs for ServiceSpec mention that port is the "patch merge key" for its ports array. Are this and the previous observation about port being the default name just forensic evidence that port existed first but we wish we'd started with name? :)

Rob Starling
  • 3,760
  • 2
  • 20
  • 38
  • Is this a dup of https://stackoverflow.com/a/41510604/1105015 ? That is, does that answer clarify that `port` _is_ what a LB has to expose, or is there value to be added by my question and answers to it? – Rob Starling Oct 20 '17 at 18:59
  • Possible duplicate of [What's the difference between ClusterIP, NodePort and LoadBalancer service types in Kubernetes?](https://stackoverflow.com/questions/41509439/whats-the-difference-between-clusterip-nodeport-and-loadbalancer-service-types) – Janos Lenart Oct 21 '17 at 08:54
  • @JanosLenart My initial comment mentioned that answer. I think it's only a dup if someone can confirm the role of `port`. We could do that there or here, but i think it's an unanswered sub-question. (That is, i don't care about the rep, I just want the answer and I think others might, too :) ) – Rob Starling Oct 21 '17 at 20:01
  • Did not notice your first comment, sorry. So, first of all the list of ports (numbers) are exposed on the ClusterIP that is assigned. Even if your service is NodePort of LoadBalancer it will still have a ClusterIP. Second, the same port numbers are exposed on the ExternalIP or LB IP (if these are assigned). Third, if you configure an Ingress object it's `backend:` section will refer to Services. The port there maybe a number but can be a string as well - which will be the port name listed in the Service. Fourth, the name is also interesting for collecting metrics with Prometheus, for example. – Janos Lenart Oct 22 '17 at 11:36

1 Answers1

0

The numeric port of a Service's ServicePort (in its spec) is used in the following places:

  • The Service is exposed at spec.clusterIP:spec.ports[*].port (unless clusterIP is set to "None")
  • The Service is exposed at spec.loadBalancerIP:spec.ports[*].port (if you specify type: LoadBalancer)
  • It is the default value for targetPort of that ServicePort
Rob Starling
  • 3,760
  • 2
  • 20
  • 38