Services, Ingress and Network Policy
Expose pods reliably inside and outside the cluster and control which pods can talk to each other.
Intermediate · about 8 hours · difficulty 3/5
Learn first: Workloads, Probes and Autoscaling, Load Balancing and Proxies
Pods come and go and change IPs, so Kubernetes provides stable networking abstractions on top of them.
The pod network
Every pod gets its own IP and can reach every other pod by default. A CNI plugin (Calico, Cilium, the cloud VPC CNI) implements this.
Services
- ClusterIP: a stable virtual IP and DNS name (
my-svc.my-ns.svc.cluster.local) that load balances to pods matching a label selector. - NodePort exposes a port on every node; LoadBalancer asks the cloud for an external load balancer.
- Headless services (no cluster IP) for StatefulSets and client-side discovery.
kubectl get endpointslicesshows which pods a service actually routes to. Empty endpoints usually means a selector or readiness problem.
Ingress and Gateway API
- An Ingress object plus an ingress controller (ingress-nginx, Traefik, cloud controllers) routes HTTP by host and path and terminates TLS.
- cert-manager automates certificates.
- The newer Gateway API separates infrastructure and route ownership and is the direction the ecosystem is moving.
NetworkPolicy
Default-allow is risky. NetworkPolicies (enforced by the CNI) let you default-deny and allow only, for example, frontend to backend on port 8080.
Good enough to move on: you can expose two services on different hostnames with TLS, debug a service with no endpoints, and lock a namespace down with a default-deny policy.
Key concepts
- Pod networking and CNI
- ClusterIP, NodePort, LoadBalancer
- Cluster DNS
- Ingress controllers
- cert-manager
- Gateway API
- NetworkPolicies
Mini project
On a local cluster, install ingress-nginx and cert-manager, expose two apps on different hostnames with TLS, then add a default-deny NetworkPolicy and allow only the traffic each app needs.
Check yourself
Your service exists but requests hang. kubectl get endpointslices shows no endpoints. What two things would you check first?
Free resources
- Services, load balancing and networking (kubernetes.io)
- Gateway API (Kubernetes SIGs)
- cert-manager (cert-manager)