Skip to content
LF Cert Trainer

Lesson 118 · Section 9: Networking

Lesson 118: Ingress: one entry point for many HTTP applications

Why a Service per application stops scaling for web traffic, what an Ingress and an Ingress controller are, how host and path rules pick a Service, how pathType, the default backend, IngressClass and TLS work, and how to write an Ingress in one kubectl command. · 20 min read · 2 min video

1/8Ingress
0:00 / 2:26

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why it exists

A Service of type NodePort or LoadBalancer exposes one application on one port. That works for a single application. With ten web applications it becomes ten cloud load balancers, ten public addresses and ten DNS records, or ten odd node ports such as :31080 that no user should have to type.

There is a second limit. A Service works at the connection level: it forwards TCP or UDP to a Pod and never looks inside. It cannot send /video to one application and /blog to another, cannot tell shop.example.com from example.com, and cannot terminate HTTPS.

Without Ingress: one load balancer per applicationClientson the internetLoad balancer 1203.0.113.10Load balancer 2203.0.113.11Load balancer 3203.0.113.12Service shoptype LoadBalancerService videotype LoadBalancerService blogtype LoadBalancer
Without Ingress: one load balancer per application. Every Service of type LoadBalancer gets its own cloud load balancer and public address. Nothing in this picture can look at a URL.

Parts:

  • Clients (on the internet)
  • Load balancer 1 (203.0.113.10)
  • Load balancer 2 (203.0.113.11)
  • Load balancer 3 (203.0.113.12)
  • Service shop (type LoadBalancer)
  • Service video (type LoadBalancer)
  • Service blog (type LoadBalancer)

Connections:

  • Clients to Load balancer 1
  • Clients to Load balancer 2
  • Clients to Load balancer 3
  • Load balancer 1 to Service shop
  • Load balancer 2 to Service video
  • Load balancer 3 to Service blog

Ingress solves both. It puts one HTTP entry point in front of the cluster and routes each request, by host name and path, to the right Service.

With Ingress: one entry point, routed by host and pathYour clusterhostpathpathClientson the internetOne address203.0.113.10Ingress controllerreverse proxy PodService shopshop.example.comService videoexample.com/videoService blogexample.com/blog
With Ingress: one entry point, routed by host and path. One address receives all web traffic. The Ingress controller reads the Host header and the path of each request and forwards it to the right Service. The Services can be plain ClusterIP.

Parts:

  • Clients (on the internet)
  • One address (203.0.113.10)
  • Ingress controller (reverse proxy Pod), in Your cluster
  • Service shop (shop.example.com), in Your cluster
  • Service video (example.com/video), in Your cluster
  • Service blog (example.com/blog), in Your cluster

Connections:

  • Clients to One address
  • One address to Ingress controller
  • Ingress controller to Service shop: host
  • Ingress controller to Service video: path
  • Ingress controller to Service blog: path

What it is

Two things with similar names, and you need both:

PartWhat it isWho provides it
IngressA namespaced API object (networking.k8s.io/v1) with routing rulesYou, per application
Ingress controllerA program that watches Ingress objects and configures a proxy (NGINX, HAProxy, Traefik, Envoy, a cloud load balancer)The cluster administrator, once per cluster
IngressClassA small cluster-wide object that gives a controller a name, so an Ingress can choose itInstalled with the controller
Two parts: the rules and the thing that obeys themapplyingressClassNamewatchwrites and reloadsYoukubectl applyIngressrules: host, pathIngressClassnames a controllerIngress controllerwatches the APIProxy configservers, locations
Two parts: the rules and the thing that obeys them. An Ingress is only data in the API server. Nothing happens until an Ingress controller that owns its class reads it and configures its proxy.

Parts:

  • You (kubectl apply)
  • Ingress (rules: host, path)
  • IngressClass (names a controller)
  • Ingress controller (watches the API)
  • Proxy config (servers, locations)

Connections:

  • You to Ingress: apply
  • Ingress to IngressClass: ingressClassName
  • Ingress to Ingress controller: watch
  • Ingress controller to Proxy config: writes and reloads

Kubernetes ships with controllers for Deployments, Jobs and nodes inside kube-controller-manager. It does not ship with an Ingress controller. A fresh kubeadm cluster stores your Ingress and nothing happens. Lesson 120 looks at how a controller is deployed and how traffic reaches it; this lesson is about the Ingress object itself.

The fields of an Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: site
  namespace: web
spec:
  ingressClassName: nginx            # which controller handles this Ingress
  defaultBackend:                    # optional: where unmatched requests go
    service:
      name: fallback
      port:
        number: 80
  tls:                               # optional: HTTPS
    - hosts: [example.com]
      secretName: example-tls
  rules:
    - host: example.com              # optional: without it the rule matches every host
      http:
        paths:
          - path: /video
            pathType: Prefix         # required
            backend:
              service:
                name: video          # a Service in the same namespace
                port:
                  number: 80         # or name: http
FieldMeaning
spec.ingressClassNameThe name of an IngressClass. Decides which controller acts on this Ingress
spec.rules[].hostThe host name to match against the request's Host header. Leave it out to match all hosts
spec.rules[].http.paths[]The paths under that host, each with a pathType and a backend
backend.service.name and portThe Service and its port (number or name, not both). Always in the Ingress's own namespace
spec.defaultBackendThe Service for requests that match no rule
spec.tls[]Host names and the Secret that holds their certificate

How it works

Matching: host first, then path

How one request finds its Servicematchno matchRequestHost + path1. Match the hostexact or wildcard2. Match the pathlongest winsServicename and portDefault backendor a 404
How one request finds its Service. The host is matched first, then the path. The longest matching path wins. A request that matches nothing goes to the default backend, or gets a 404 from the controller.

Parts:

  • Request (Host + path)
  • 1. Match the host (exact or wildcard)
  • 2. Match the path (longest wins)
  • Service (name and port)
  • Default backend (or a 404)

Connections:

  • Request to 1. Match the host
  • 1. Match the host to 2. Match the path
  • 2. Match the path to Service: match
  • 2. Match the path to Default backend: no match
  1. The controller compares the request's Host header with the host of every rule. A rule without host matches any host.
  2. Among the rules for that host, it compares the URL path with each path, using that path's pathType.
  3. If several paths match, the longest one wins. If two are equally long, Exact beats Prefix.
  4. If nothing matches, the request goes to spec.defaultBackend. When that is not set, the controller answers itself, usually with a 404.

Path types

pathType is required on every path. There are three values:

pathTypeMatchesExample: path /video
PrefixThe path, element by element, split at //video, /video/, /video/42 match. /videos does not
ExactExactly this path, case sensitiveOnly /video. Not /video/
ImplementationSpecificWhatever the controller decidesUsed for regular expressions, see the next lesson

The detail that surprises people is that Prefix is not a string prefix. It compares whole path segments: /video matches /video/42 but not /videos, because videos is a different segment. Prefix with path / matches everything, which makes it the usual catch-all.

Hosts and wildcards

hostRequest hostMatch?
shop.example.comshop.example.comYes
*.example.comshop.example.comYes
*.example.comexample.comNo: the wildcard needs one label
*.example.coma.shop.example.comNo: the wildcard covers exactly one label
(none)anythingYes

A host is a DNS name, never an IP address, and it carries no port.

IngressClass: which controller owns this Ingress

A cluster may run several controllers, for example one for public traffic and one for internal traffic. Each has an IngressClass:

apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  name: nginx
  annotations:
    ingressclass.kubernetes.io/is-default-class: "true"   # optional
spec:
  controller: k8s.io/ingress-nginx      # the controller that implements this class

An Ingress chooses one with spec.ingressClassName. If you leave the field out and exactly one IngressClass is marked as default, the API server fills it in for you. If no class is the default, an Ingress without a class is usually ignored by every controller: it exists, it has no address, and nothing routes.

TLS

The controller can terminate HTTPS. The certificate and key live in a Secret of type kubernetes.io/tls, in the same namespace as the Ingress:

kubectl -n web create secret tls example-tls --cert=tls.crt --key=tls.key
spec:
  tls:
    - hosts:
        - example.com               # must match a host in the rules and a name in the certificate
      secretName: example-tls
  rules:
    - host: example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 80

The client speaks HTTPS to the controller; the controller speaks plain HTTP to the Pods, unless you configure it otherwise. An Ingress only describes ports 80 and 443. To expose a database, a message broker or anything else that is not HTTP, use a Service of type NodePort or LoadBalancer.

Under the hood · Ingress today: frozen, still everywhere, and what replaces it
  • The Ingress API is frozen. It is generally available and will stay in Kubernetes, but it gets no new features. The Kubernetes project recommends the Gateway API for new work; lessons 121 and 122 cover it. Both are in the CKA curriculum, so learn both.
  • Why it was frozen. Ingress only knows hosts, paths and TLS. Everything else, such as rewrites, redirects, timeouts, header changes or traffic splitting, had to go into controller-specific annotations, which differ from controller to controller. The next lesson shows that mechanism.
  • Controllers come and go. The widely used community controller ingress-nginx was retired in March 2026 and receives no further releases. Existing installations keep working, and practice environments still use it, but new clusters should pick a maintained controller or the Gateway API. The Ingress object you write is the same with any controller; only the class name and the annotations change.
  • Several Ingresses for one host. Different teams may each create an Ingress for example.com with different paths. Most controllers merge them into one virtual host. What happens when two of them claim the same path is up to the controller, so avoid it.
  • Resource backends. Instead of service, a backend can be a resource reference to another object in the namespace, such as a storage bucket. It is rare and controller specific.

Types of Ingress

ShapeLooks likeUse it when
Single ServiceOnly defaultBackend, no rulesOne application behind the entry point
Simple fanoutOne host, several pathsexample.com/video and example.com/blog are different applications
Name-based virtual hostingSeveral hosts, each with path /shop.example.com and blog.example.com are different applications
TLSAny of the above plus spec.tlsThe site must be served over HTTPS

They combine freely: several hosts, each with several paths, some with TLS.

Using it

Example · Fanout: two applications under one host

Services video and blog exist in namespace web, both on port 80. Route example.com/video and example.com/blog to them.

kubectl -n web create ingress site --class=nginx \
  --rule="example.com/video*=video:80" \
  --rule="example.com/blog*=blog:80"

The rule format is host/path=service:port. A path that ends in * becomes pathType: Prefix (without the star in the path); any other path becomes Exact. Check what was created:

kubectl -n web describe ingress site
Name:             site
Namespace:        web
Address:          203.0.113.10
Ingress Class:    nginx
Default backend:  <default>
Rules:
  Host         Path  Backends
  ----         ----  --------
  example.com
               /video   video:80 (10.244.1.7:8080,10.244.2.4:8080)
               /blog    blog:80 (10.244.1.9:8080)

The addresses in brackets are the Pods behind each Service. If they are there, the Service name, the port and the Service's selector are all correct.

Example · Virtual hosts, with a catch-all

shop.example.com goes to Service shop on port 8080, blog.example.com to Service blog on port 80, and anything else to Service landing.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hosts
  namespace: web
spec:
  ingressClassName: nginx
  defaultBackend:
    service:
      name: landing
      port:
        number: 80
  rules:
    - host: shop.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: shop
                port:
                  number: 8080
    - host: blog.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: blog
                port:
                  number: 80

The same thing in one command:

kubectl -n web create ingress hosts --class=nginx \
  --default-backend=landing:80 \
  --rule="shop.example.com/*=shop:8080" \
  --rule="blog.example.com/*=blog:80"

Example · Add HTTPS to a host

Create the Secret, then name it in the rule with ,tls=:

kubectl -n web create secret tls shop-tls --cert=shop.crt --key=shop.key
kubectl -n web create ingress shop --class=nginx \
  --rule="shop.example.com/*=shop:8080,tls=shop-tls"
kubectl -n web get ingress shop
NAME   CLASS   HOSTS              ADDRESS        PORTS     AGE
shop   nginx   shop.example.com   203.0.113.10   80, 443   12s

443 in the PORTS column tells you the Ingress has a tls section.

Example · Test an Ingress without DNS

The host name in the rule rarely resolves in a lab. Send the request to the controller's address and set the Host header yourself:

curl -H "Host: example.com" http://203.0.113.10/video
# for HTTPS, let curl map the name to the address so that TLS uses the right host name
curl -k --resolve shop.example.com:443:203.0.113.10 https://shop.example.com/

Without the right Host header no rule with a host matches, and you get the controller's 404 even though the Ingress is correct.

Tricks

Common mistakes

  • No Ingress controller, or the wrong class. The Ingress is created, ADDRESS stays empty and nothing answers. Check kubectl get ingressclass and spec.ingressClassName.
  • Backend Service in another namespace. An Ingress can only name Services in its own namespace. Create the Ingress where the Service lives.
  • Using the Pod port. port.number is the Service's port, not the container port or targetPort.
  • Leaving out pathType. The API server rejects the Ingress: the field is required.
  • Expecting /video to match /videos. Prefix compares whole segments.
  • Forgetting the star in kubectl create ingress. --rule="example.com/video=video:80" creates an Exact path, so /video/42 does not match.
  • Testing by IP address without a Host header. Rules with a host only match that host.
  • TLS Secret in the wrong namespace or of the wrong type. It must be kubernetes.io/tls, with tls.crt and tls.key, next to the Ingress.
  • Using Ingress for non-HTTP traffic. It only covers HTTP and HTTPS.

Recap

  • An Ingress is a list of HTTP routing rules; an Ingress controller is the proxy that obeys them. You need both.
  • ingressClassName picks the controller. Rules match the host first, then the longest path.
  • pathType is required: Prefix matches by path segment, Exact matches one path only.
  • Backends are Services, by name and Service port, in the Ingress's own namespace. ClusterIP is enough.
  • kubectl create ingress NAME --class=C --rule="host/path*=svc:port[,tls=secret]" writes it for you; kubectl describe ingress proves it.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

3 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Publish three Services through the cluster's ingress controller: two host names, and one path that goes to its own backend.

    Build · Level 2 · standard · target 15 min

  • Section capstone. Repair a Service and a Pod's name resolution, then move the shop from an Ingress to a Gateway with routes that keep its paths, strip a prefix and redirect an old host name.

    Build · Level 3 · challenge · target 35 min

  • An Ingress exists, yet its host answers 404. Follow a request from the controller to the pods and repair every broken link.

    Fix · Level 3 · challenge · target 15 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.