Pods Should Call Each Other by Service Name, Not Through the Ingress

In progress Kubernetes Networking

Every Kubernetes Service gets a DNS name inside the cluster, and a pod reaches another app most directly through that name. The ingress host name (radarr.homelab.local) is built for clients outside the cluster. Using it between pods sends traffic out through the load balancer and the ingress controller and back in, and makes app-to-app links depend on external DNS and TLS. When an app asks for "the URL of the other app", the answer inside the cluster is the Service name.

Which Name Resolves Where

Name Resolves Use from
radarr the Service in the same namespace pods in that namespace
radarr.media or radarr.media.svc.cluster.local the Service in namespace media pods in any namespace
radarr.homelab.local the ingress, through the LAN's DNS browsers and devices outside the cluster

CoreDNS answers the first two from the cluster's Service records. The third depends on the LAN's DNS and on the ingress controller being up.

Use the Service Port, Not the Container Port

A Service can listen on one port and forward to another: port: 80 to targetPort: 8080. Clients of the Service use port. Pointing an app at qbittorrent:8080 fails when the Service only listens on 80, even though the container itself listens on 8080.

When the External Name Is Right

Links that a user's browser follows (a redirect, a link shown in a page, an OAuth callback) must use the external name, because the browser isn't in the cluster. The rule is to ask who makes the request: a pod uses the Service, a person uses the ingress.

References

Review cards

Flashcard Sonarr reaches qBittorrent through its ingress host name. What breaks it that a Service name wouldn't?

The ingress controller restarting, or the LAN's DNS or the external name changing. The traffic also leaves the cluster and comes back through TLS for nothing; the Service name stays inside the cluster.

Flashcard From another namespace, which names reach the Service radarr in namespace media?

radarr.media or radarr.media.svc.cluster.local. The short name radarr only works from inside media.

Flashcard A Service maps port 80 to targetPort 8080. Why does http://qbittorrent:8080 fail from another pod?

Clients of a Service must use its port (80). The Service doesn't listen on the container's 8080.