Services and Ingress: Let Traffic Find Your App

Pods change, but your app address should not. Learn Services for internal traffic and Ingress for web traffic.

Beginner⏱ 2 min readLesson 5 of 16#kubernetes#service#ingress#networking#dns

The problem

Pods are replaceable. A replacement pod gets a new IP address. Other apps should not need to discover that new address every time.

A Service gives a group of pods one stable name. An Ingress routes HTTP/HTTPS traffic from outside the cluster to a Service.

Ingress routes outside HTTP traffic to Services, which load-balance across pods

Drawing diagram…

Service: the stable internal address

apiVersion: v1
kind: Service
metadata:
  name: shop-api
spec:
  selector:
    app: shop-api
  ports:
    - port: 80
      targetPort: 3000

Read this as: “When someone calls shop-api on port 80, send the request to port 3000 of ready pods labelled app: shop-api.”

Inside the same namespace, another app can call:

http://shop-api

Kubernetes DNS turns that name into the right destination. Do not put pod IP addresses in application configuration.

Service types: pick the simple one first

TypeWhat it meansTypical use
ClusterIPReachable only inside the clusterDefault; app-to-app traffic
LoadBalancerCloud creates a public load balancerDirectly expose one service
NodePortOpens a port on each nodeLearning or special setups

Start with ClusterIP for internal services. Use Ingress for most public web traffic.

Ingress: one public front door

An Ingress can route different domains and paths to different Services.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: shop
spec:
  ingressClassName: nginx
  rules:
    - host: api.shop.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: shop-api
                port:
                  number: 80

Important: an Ingress YAML file alone does nothing. Your cluster also needs an Ingress controller (for example NGINX, Traefik, or a cloud controller) that reads these rules and handles the incoming connections.

HTTPS certificates are often added with cert-manager, which can request and renew certificates automatically.

When traffic does not arrive

Check in this order:

kubectl get pods -l app=shop-api
kubectl get svc shop-api
kubectl get endpointslices
kubectl describe svc shop-api

The most common cause is a label mismatch: the Service selects app: shop-api, but the pods have a different label. The second common cause is that pods are not ready, so Kubernetes correctly removes them from the Service.

Remember this

  • Pods change; Services provide a stable name.
  • A Service sends traffic only to ready pods whose labels match its selector.
  • Use Service DNS names, not pod IPs.
  • Ingress is the web-routing rule; an Ingress controller is the software that enforces it.