There seems to be two contradictory explanations of how NodePort services route traffic. Services can route traffic to one of the two, not both:
- Nodes (through the kube-proxy) According to
kubectl explain Service.spec.externalTrafficPolicy
and this article that adds more detail, packets incoming to NodePort services withService.spec.externalTrafficPolicy=Local
set get routed to a kube-proxy, which then routes the packets to the corresponding pods its running.- This kube-proxy networking documentation further supports this theory adding that endpoints add a rule in the service's IPtable that forwards traffic to nodes through the kube-proxy.
- Pods: services update their IPtables from
endpoints
, which contain the IP addresses for the pods they can route to. Furthermore, if you remove your service's label selectors and edit endpoints you can change where your traffic is routed to.
If one of these is right, then I must be misunderstanding something.
- If services route to nodes, then why can I edit
endpoints
without breaking the IPtables? - If services route to pods, then why would services go through the trouble of routing to nodes when
Service.spec.externalTrafficPolicy
is set?