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

  1. Show IP of the LoadBalancer
1
2
minikube ip
192.168.49.2
  1. update localhost /etc/hosts file example
1
2
192.168.178.50 demo.nginx.local
192.168.178.50 demo1.nginx.local

Rancher Desktop

Assuming ingress-nginx is installed following nginx-ingress-rancher-destop in ingress-nginx namespace.

  1. Show IP of the LoadBalancer

    • Get ingress-nginx service to find the external-ip
    1
    2
    3
    
    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
    1
    2
    3
    
    kubectl get ingress -A
    NAMESPACE   NAME                  CLASS    HOSTS              ADDRESS          PORTS   AGE
    demo       demo-development       <none>   demo.nginx.local   192.168.178.50   80      8d
    
  2. Update /etc/hosts file with the external IP example

1
2
192.168.178.50 demo.nginx.local
192.168.178.50 demo1.nginx.local

We could do the same if we are using traefik ingress that comes pre-enabled in rancher-desktop

1
2
192.168.178.50 demo.traefik.local
192.168.178.50 demo1.nginx.local