Challenge - Ingress
- Docker & Kubernetes course
- Advanced
- Lesson 66/70
- 5 min
Write an Ingress with path-based routing.
Challenge: a multi-service Ingress
In this challenge you'll publish two domain names and three services with a single Ingress; the main domain will have HTTPS:
magaza.example.com/ -> web:80
magaza.example.com/api -> api:8000
panel.example.com/ -> panel:80Testing doesn't wait for real DNS: the request is sent to the controller address and the domain name is given with the Host header.
Practice Ingress rules
Write an Ingress's rules section (starting with rules:): for magaza.example.com, /api (Prefix) → api:8000 and / (Prefix) → web:80; for panel.example.com, / (Prefix) → panel:80.
Starter code
# buraya yazSample solution
rules:
- host: magaza.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api
port:
number: 8000
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
- host: panel.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: panel
port:
number: 80Expected output
ingress.networking.k8s.io/magaza configured
Practice TLS and testing
Write three commands: create the magaza-tls TLS Secret from magaza.crt and magaza.key; test the API path with curl -s -H "Host: magaza.example.com" http://$(minikube ip)/api/saglik; test the panel with curl -s -H "Host: panel.example.com" http://$(minikube ip)/.
Starter code
# buraya yazSample solution
kubectl create secret tls magaza-tls --cert=magaza.crt --key=magaza.key
curl -s -H "Host: magaza.example.com" http://$(minikube ip)/api/saglik
curl -s -H "Host: panel.example.com" http://$(minikube ip)/Expected output
secret/magaza-tls created
{"durum":"ok"}
<!doctype html><title>Yönetim paneli</title>
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Where does a request to panel.example.com/api go with these rules?
- api:8000
- web:80
- 404
- panel:80 (only its own host rules apply) Correct answer
Explanation: The host matches first, then that host's paths.
2 Give the domain name with a header.
curl -H "____: panel.example.com" http://$(minikube ip)/
curl -H "Host: panel.example.com" http://$(minikube ip)/
Explanation: The Ingress reads the host from the Host header.
3 Match.
| Term | Meaning |
|---|---|
rules[].host |
Domain rule |
paths[].path |
Path rule |
tls[].hosts |
HTTPS domains |
Host header |
Testing without DNS |