liveBook · Manning

Targetport field

As explained in Kubernetes in Action, Second Edition

The targetPort field specifies the port on selected pods to which a Kubernetes Service forwards traffic.

The targetPort field tells a Kubernetes Service which port to use on the selected pods. A Service can accept traffic on one port and forward it to a different pod port. section 11.1.2

Forwarding Service traffic to port 80

In the quote Service, port 80 is both the Service-facing port and the targetPort. The selector chooses pods labeled app=quote, and each connection is forwarded to port 80 on a selected pod. section 11.1.2

Instead of a number, targetPort can name a port declared in the pod’s container port list. Named ports let the Service continue using the correct destination when pods use different port numbers. section 11.1.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines numeric and named destination ports, but does not detail endpoint management or Service types.
Examples
Uses the quote Service manifest with port 80, targetPort 80, and app=quote-selected pods.
What you can do after
Operate/configure a Service to forward traffic to numeric or named ports on selected pods.
How it connects
Links Services with pods, label selectors, container port lists, and Service ports.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.