Route traffic with an ingress
In this task you'll put several apps behind one address with path routing.
An ingress controller is one front door for HTTP traffic. Ingress rules send requests to services by host name or path, so apps don't each need a public IP.
AKS's application routing add-on installs a managed NGINX controller; its ingress class is webapprouting.kubernetes.azure.com.
Example. SS Kaiser serves /shop and /api from one address; both services are ClusterIP, so the ingress is the only way in.
Costs money. This task creates resources that are charged while they exist. Delete them as soon as you finish.
Before you start
You need: An AKS cluster. Time: 20 minutes.
Where to look
- az aks approuting enable
- Ingress YAML
- kubectl get ingress
Steps
- Run
az aks approuting enable -g <group> -n <cluster>. - Apply an Ingress with ingressClassName webapprouting.kubernetes.azure.com and paths /shop and /api.Add nginx.ingress.kubernetes.io/rewrite-target: / if the apps only answer on /.
- Change the apps' services to ClusterIP, then
kubectl get ingressfor the address.
Commands
# Connect kubectl to the cluster first
az aks get-credentials -g <group> -n <cluster>
az aks approuting enable -g <group> -n <cluster>
kubectl apply -f ingress.yaml
kubectl get ingress -A
Watch out for
- Cost
- One public IP for the ingress instead of one per app.
- Security
- Add TLS (cert-manager or Key Vault certificates) before real traffic, and keep internal services ClusterIP.
- Common mistakes
- Leaving the old LoadBalancer services in place, and path rules that don't match how the app builds its links.
Clean up
kubectl delete ingress <name>; az aks approuting disable removes the add-on.
Words to know
- Ingress
- Routing rules for HTTP(S) traffic into the cluster.
- Ingress class
- Which controller handles an Ingress.
- ClusterIP
- A service reachable only inside the cluster.
Tick off each step and track your progress in the guide.
Open this task in DevOps, Hands On