Kubernetes Ingress: Expose Multiple HTTP Backends the Imperative Way
Three teams share the same Kubernetes cluster, each running their service in a separate namespace. Your job is to expose each service at its own hostname using Ingress resources, with Traefik as the ingress controller.
Verify what is already running:
kubectl get pods -A | grep app
kubectl get svc -A | grep app-svc
kubectl get ingressclass
Step 1 - Create an Ingress for Each Team
Create an Ingress named app-ingress in each team namespace.
Requirements:
ingressClassName: traefikteam-v1/app-ingress: hostapp-v1.local, path/- backendapp-svc:5678(pathType: Prefix)team-v2/app-ingress: hostapp-v2.local, path/- backendapp-svc:5678(pathType: Prefix)team-v3/app-ingress: hostapp-v3.local, path/- backendapp-svc:5678(pathType: Prefix)
Hint: Creating an Ingress imperatively
Personally, I find imperative commands much easier to memorize than YAML file structure and I use them whenever I can. kubectl create ingress covers all the fields you need. Run kubectl create ingress --help to see all flags. The --rule format is host/path=service:port — append * to the path to get pathType: Prefix.
Step 2 - Verify Traffic
Test each team's service by sending a request to Traefik on port 80 with the correct Host header:
curl -H "Host: app-v1.local" http://localhost/
curl -H "Host: app-v2.local" http://localhost/
curl -H "Host: app-v3.local" http://localhost/
Step 3 - Path-Based Ingress with a Catch-All Rule
The platform namespace has three services: api, admin, and frontend. Create a single Ingress named path-ingress in platform that routes by path instead of hostname.
Unlike the host-based Ingresses above, all backends are in the same namespace so one Ingress can reference all three.
Requirements:
ingressClassName: traefik- host
app.local, path/api- backendapi:5678(pathType: Prefix) - host
app.local, path/admin- backendadmin:5678(pathType: Prefix) - host
app.local, path/- backendfrontend:5678(pathType: Prefix, catch-all)
Step 4 - Verify Path Routing
curl -H "Host: app.local" http://localhost/api
curl -H "Host: app.local" http://localhost/admin
curl -H "Host: app.local" http://localhost/unknown