It is useful to configure hostnames for kubernetes ingresses when testing kubernetes application locally on a developer’s machine.
We may add LoadBalancer IP address to /etc/hosts file to be able to open ingress hostname in browsers.
Minikube#
- Show IP of the LoadBalancer
minikube ip
192.168.49.2- update localhost
/etc/hostsfile example
192.168.178.50 demo.nginx.local
192.168.178.50 demo1.nginx.localRancher Desktop#
Assuming ingress-nginx is installed following nginx-ingress-rancher-destop in ingress-nginx namespace.
Show IP of the LoadBalancer
- Get
ingress-nginxservice to find theexternal-ip
kubectl get service -n ingress-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-nginx-controller LoadBalancer 10.43.49.110 192.168.178.50 80:32170/TCP,443:30682/TCP 8d- Another approach to find the address could be to view the ingresses
kubectl get ingress -A NAMESPACE NAME CLASS HOSTS ADDRESS PORTS AGE demo demo-development <none> demo.nginx.local 192.168.178.50 80 8d- Get
Update /etc/hosts file with the external IP example
192.168.178.50 demo.nginx.local
192.168.178.50 demo1.nginx.localWe could do the same if we are using traefik ingress that comes pre-enabled in rancher-desktop
192.168.178.50 demo.traefik.local
192.168.178.50 demo1.nginx.local