Kubernetes networking: Services, Ingress and Gateway
Pods come and go, and each new Pod gets a new IP address. Networking in Kubernetes is about putting stable names in front of that churn: a Service gives a set of Pods one virtual IP and DNS name inside the cluster, and Ingress or Gateway API routes HTTP traffic from outside the cluster to those Services. This page follows a request for the invented OrdersPortal application from a browser at orders.example.test to the orders-api Pods defined on the workloads page.
The manifests were validated against the Kubernetes 1.37 API schemas with kubernetes-validate (the Gateway API HTTPRoute is a custom resource outside those schemas and was checked against the kubernetes.io example instead). No cluster was available, so kubectl commands are not run here.
Topics on this page
Section titled “Topics on this page”| Topic | What it answers |
|---|---|
| Services | How a Service selects Pods and load-balances across them. |
| Service types | ClusterIP, NodePort, LoadBalancer, ExternalName and headless Services. |
| Cluster DNS and EndpointSlices | How names resolve and how to see which Pods a Service is sending to. |
| Ingress | Host- and path-based HTTP routing, TLS, and why an Ingress needs a controller. |
| Gateway API | The recommended successor to Ingress and how its roles split the work. |
Services
Section titled “Services”A Service is a stable endpoint for a changing set of Pods. It selects Pods by label, gets a virtual IP (the cluster IP) and a DNS name, and spreads connections across the Pods that are currently ready. Pods that fail their readiness probe are removed from the Service automatically, which is how rolling updates avoid sending traffic to Pods that are still starting.
apiVersion: v1kind: Servicemetadata: name: orders-api namespace: ordersportalspec: type: ClusterIP selector: app.kubernetes.io/name: orders-api ports: - name: http port: 80 # the port clients use targetPort: http # the named container port (8080) on the Podsport is what clients connect to; targetPort is where the Pods listen. Using the container port’s name (http) instead of the number lets you change the container port without touching the Service. On a typical cluster, kube-proxy (or a CNI plugin that replaces it) programs each node so that traffic to the cluster IP is forwarded to one of the ready Pods. Load balancing is per connection, not per request, so long-lived connections such as gRPC streams stay on one Pod.
Pitfalls:
- Selector does not match the Pod labels. The Service exists but has no endpoints and connections are refused. Compare
kubectl get pods --show-labelswith the selector. - Pointing
targetPortat the wrong port. The Service has endpoints but every connection fails; check the container’scontainerPortand the port the process actually binds.
Service types
Section titled “Service types”The type field controls how far the Service is reachable:
- ClusterIP (default): reachable only inside the cluster. Use it for service-to-service traffic and behind Ingress or Gateway.
- NodePort: also opens the same port on every node, allocated by default from 30000 to 32767, so
<node-ip>:<node-port>reaches the Service. Useful for development and for external load balancers you manage yourself. - LoadBalancer: also asks the cloud provider (or an on-premises implementation such as MetalLB) to provision an external load balancer with its own address. Simple, but each Service gets its own load balancer, which costs money and an IP per Service.
- ExternalName: no proxying at all; the Service name becomes a DNS CNAME for an external host. Handy for giving an external database a cluster-local name during a migration.
- Headless (
clusterIP: None): no virtual IP; DNS returns the individual Pod IPs. StatefulSets use it so clients can addressorders-db-0,orders-db-1directly.
For HTTP services, the usual production shape is ClusterIP Services behind one shared entry point (an Ingress controller or Gateway), with a single LoadBalancer Service in front of that entry point. Non-HTTP protocols such as a TCP message broker are a common reason to use a LoadBalancer Service directly.
Pitfalls:
- A LoadBalancer per microservice. Costs grow linearly and TLS is configured in many places. Route HTTP through a shared entry point.
- Exposing NodePorts on internet-facing nodes. Every node then accepts traffic for every NodePort Service; restrict it with firewalls or avoid it.
Cluster DNS and EndpointSlices
Section titled “Cluster DNS and EndpointSlices”The cluster DNS service (CoreDNS on most clusters) creates a record for every Service: <service>.<namespace>.svc.cluster.local. Pods in the same namespace can use the short name (http://orders-api), and Pods in other namespaces use orders-api.ordersportal or the full name. Pods are configured with search domains that make the short forms work.
Behind each Service, the control plane maintains EndpointSlices that list the IP addresses and ports of the matching Pods and whether each is ready. They are what kube-proxy reads. The older Endpoints API is deprecated since Kubernetes 1.33; use EndpointSlices when you inspect or create endpoints yourself.
# Not run here: needs a clusterkubectl get endpointslices -n ordersportal -l kubernetes.io/service-name=orders-apikubectl run dns-check -n ordersportal --rm -it --image=busybox:1.37 --restart=Never -- nslookup orders-apiWhen a Service “does not work”, these two commands answer the first questions: does the name resolve, and are there ready endpoints behind it?
Pitfalls:
- Hard-coding Pod IPs or cluster IPs in configuration. Use DNS names; Pod IPs change on every restart.
- Assuming cross-namespace access is blocked. Namespaces are not a network boundary. Use NetworkPolicies, enforced by your CNI plugin, to restrict traffic.
Ingress
Section titled “Ingress”An Ingress is an API object that describes HTTP and HTTPS routing from outside the cluster to Services, based on host names and URL paths. It lets many Services share one external load balancer and one place for TLS termination.
An Ingress object does nothing on its own. An Ingress controller, a proxy running in the cluster such as one provided by your cloud or a third-party project, watches Ingress objects and configures itself. ingressClassName selects which controller handles an Ingress, which matters when a cluster runs more than one.
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: ordersportal namespace: ordersportalspec: ingressClassName: example-ingress tls: - hosts: - orders.example.test secretName: orders-example-test-tls rules: - host: orders.example.test http: paths: - path: /api pathType: Prefix backend: service: name: orders-api port: name: http - path: / pathType: Prefix backend: service: name: orders-web port: name: httppathType is required: Exact matches one path exactly, Prefix matches by path segments (/api matches /api and /api/orders but not /apiv2), and ImplementationSpecific leaves matching to the controller. The tls section references a Secret of type kubernetes.io/tls holding the certificate and key; cert-manager is a common way to issue and renew it automatically.
Two facts shape new Ingress work in 2026. The Ingress API is frozen: it remains generally available and Kubernetes has no plans to remove it, but it receives no new features, and the Kubernetes project recommends Gateway API instead. And the community Ingress NGINX controller (kubernetes/ingress-nginx) was retired: best-effort maintenance ended in March 2026, so there are no further releases or security fixes. Existing installations keep working, but SIG Network recommends migrating to Gateway API or another Ingress controller. Controller-specific features also live in annotations, so an Ingress written for one controller rarely moves to another unchanged.
Pitfalls:
- No
ingressClassName. The Ingress is ignored unless a default IngressClass exists, or picked up by the wrong controller. - Relying on controller annotations for core behavior. Rewrites, timeouts and auth via annotations tie you to one controller; that is exactly what makes migrations off retired controllers expensive.
Gateway API
Section titled “Gateway API”Gateway API is the newer, extensible set of APIs for traffic routing (gateway.networking.k8s.io), developed by SIG Network as the successor to Ingress. It is role-oriented: a cluster operator or platform team installs a controller and defines a GatewayClass, a platform team creates a Gateway that listens on addresses and ports with TLS settings, and application teams attach HTTPRoute (or GRPCRoute, TLSRoute and other route) objects in their own namespaces. That split matches how organizations work and removes the annotation sprawl of Ingress, because features such as header matching, traffic splitting and request mirroring are part of the API.
Gateway API types are custom resources, so the CRDs and a conformant implementation must be installed in the cluster. Here OrdersPortal attaches routes to a shared Gateway owned by the platform team:
apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata: name: ordersportal namespace: ordersportalspec: parentRefs: - name: shared-gateway namespace: gateway-infra hostnames: - orders.example.test rules: - matches: - path: type: PathPrefix value: /api backendRefs: - name: orders-api port: 80 - backendRefs: - name: orders-web port: 80The Gateway’s listener decides which namespaces may attach routes, so the platform team keeps control of the entry point while each team manages its own routing. The ingress2gateway tool converts existing Ingress objects into Gateway API resources as a starting point for migration.
Pitfalls:
- Route not attached. If the Gateway’s
allowedRoutesdoes not admit the route’s namespace or the hostname does not match a listener, the route is ignored. Check the route’sstatus.parentsconditions. - Assuming every feature is portable. Core features are tested for conformance; extended and implementation-specific features vary. Check your implementation’s conformance report.
Choosing between them
Section titled “Choosing between them”| You need | Use |
|---|---|
| Service-to-service traffic inside the cluster | ClusterIP Service and DNS name |
| Direct addressing of each replica | Headless Service with a StatefulSet |
| A non-HTTP protocol exposed outside the cluster | LoadBalancer Service |
| HTTP routing on a cluster that already runs a supported Ingress controller | Ingress with an explicit ingressClassName |
| New HTTP routing, or migrating off Ingress NGINX | Gateway API with HTTPRoute |
| A cluster-local name for an external dependency | ExternalName Service |
Interview questions
Section titled “Interview questions”How does a Service know which Pods to send traffic to? Through its label selector. The control plane keeps EndpointSlices listing the matching Pods and their readiness; kube-proxy or the CNI plugin routes the cluster IP to ready endpoints only.
What is the difference between port, targetPort and nodePort?
port is the Service’s port on its cluster IP, targetPort is the port on the Pods that traffic is forwarded to, and nodePort is the port opened on every node for NodePort and LoadBalancer Services.
Why would you choose Ingress or Gateway over a LoadBalancer Service for each app? One entry point serves many Services, so you pay for one load balancer, manage TLS in one place, and route by host and path. LoadBalancer per Service is simpler but costly and spreads configuration out.
What changed for Ingress NGINX users in 2026? The project was retired after best-effort maintenance ended in March 2026: no more releases or security fixes. Existing deployments keep running, but users are advised to migrate to Gateway API or another Ingress controller.
Senior scenario: you must migrate twenty OrdersPortal Ingress objects off Ingress NGINX without downtime. What is your plan?
Inventory the Ingresses and every nginx.ingress.kubernetes.io annotation they rely on, since those behaviors must be re-expressed. Install a Gateway API implementation alongside the old controller with its own load balancer address, convert the objects (ingress2gateway gives a first draft), and test each route against the new address with the real host header. Cut over DNS gradually, with low TTLs and the old controller still serving, then monitor error rates and latency before removing the old controller and its annotations.
Related pages
Section titled “Related pages”- Kubernetes workloads: Pods and Deployments: the Pods these Services select.
- Kubernetes configuration: ConfigMaps, Secrets, namespaces and Helm: TLS Secrets and namespaces.
- Kubernetes introduction
- Docker volumes and networking: how container networking works on a single host.