Kubernetes · Chapter 19 of 28
Ingress
By the end of this chapter you can put several Services behind one web address with an Ingress, send each path to the right Service, read what the ingress controller's 404, 503 and 502 mean, and serve the address over HTTPS with a certificate kept in a Secret. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: More workloads and traffic
- 4 tasks
- Kubernetes
- In the all labs plan
The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.
Why you need this
On Dhanteras evening Jhatpat's customers open lucknow.jhatpat.in about 1,200 times a second. The same address serves three kinds of callers: the customer app and website (the storefront), the rider app that 1,900 riders keep open to see where they are going (rider-tracker), and the tablets in the 14 dark stores, which read the catalog. Ritika wants one address, always over HTTPS, so that the browser shows a lock and nobody can read a customer's phone number on a café's Wi-Fi.
Chapter 8 gave you two ways in from outside, and neither fits. A NodePort opens one port per Service on every node: http://10.20.0.11:31780/ is no address to print on a delivery bag, and three Services mean three ports. A LoadBalancer gives each Service its own address, which on a cloud is a paid load balancer per Service, and still no way to say "/riders goes to rider-tracker". Neither has a place for the HTTPS certificate: each app would have to carry it. Jhatpat needs one front door that reads the host and the path of every request and sends it to the right Service, with the certificate kept at the door.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
lucknow-ingress.yaml: one host, two Services
Send one host to two Services, by path.
1. Open lucknow-ingress.yaml. Make an Ingress named lucknow in ch19, with class nginx, for the host lucknow.jhatpat.in.
2. Send / and every path under it to the Service storefront on port 80.
3. Send /riders and every path under it (such as /riders/nearest) to the Service rider-tracker on port 80.
4. Apply the file. Try the addresses with lab curl.
To pass: lab curl http://lucknow.jhatpat.in/ is answered 200 by storefront. /riders and /riders/nearest are answered 200 by rider-tracker. The Services storefront and rider-tracker stay as they are: one port, 80 to targetPort 8080.
- Task 2
catalog-ingress.yaml: fix the Ingress that answers 503
Tushar's Ingress catalog (host catalog.jhatpat.in) answers 503. Find why and fix it.
1. Run lab curl http://catalog.jhatpat.in/products. Read the lab line under the answer.
2. Describe the Ingress catalog. Compare it with the Service catalog.
3. Fix the mistake in catalog-ingress.yaml. Apply the file.
4. Run lab curl on the same address again.
To pass: lab curl http://catalog.jhatpat.in/products is answered 200 by a catalog pod with the product list. Fix the Ingress, not the Service: the Service catalog keeps one port, 80 to targetPort 8080.
- Task 3
TLS for lucknow.jhatpat.in
Serve lucknow.jhatpat.in over https with your own certificate.
1. Use openssl to make a self-signed certificate and key. Its CN or a DNS name in it is lucknow.jhatpat.in.
2. Save them in ch19 in a Secret named lucknow-tls, of type kubernetes.io/tls.
3. In lucknow-ingress.yaml, add a tls section for the host lucknow.jhatpat.in with the Secret lucknow-tls. Apply the file.
4. Run lab curl https://lucknow.jhatpat.in/ without -k.
To pass: the certificate names lucknow.jhatpat.in and has not expired. https://lucknow.jhatpat.in/ is answered 200 by storefront without -k. The /riders route of task 1 still works.
- Task 4 · interview question
Interview: the Ingress and the controller
Interview question: what does an Ingress object do, and what does the ingress controller do?
1. Open answer.txt. Write below the lines that start with #.
2. In a sentence or two of your own, say what the Ingress object has in it.
3. Name the ingress controller, and say what it does with the requests.
To pass: your answer says what the Ingress has in it, names the controller (or nginx), and says what the controller does with the requests. Lines that start with # do not count. Ammar will ask: "You wrote an Ingress, and requests arrived. Which part did the work?"
What you will learn
- The ingress controller: the program that receives the traffic (ingress-nginx in the lab).
- The Ingress: rules that say which host and path go to which Service and port.
- Paths: pathType Prefix and Exact, the longest match wins, several Services behind one host.
- Rewrites and defaultBackend: changing the path on the way, and a catch-all.
- The controller's errors: what 404, 503 and 502 tell you.
- TLS: a certificate in a Secret of type kubernetes.io/tls, named in the Ingress.
More in More workloads and traffic
Build "Ingress" yourself
Jhatpat delivers groceries in ten minutes from 14 dark stores across Lucknow, and its hand-run servers fall over on festival evenings. You move it onto Kubernetes. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.