kubernetes - nginx ingress - How to access

7/27/2020

I could not access my application from the k8s cluster. With nodePort everything works. If I use ingress controller, I could see that it is created successfully. I am able to ping IP. If I try to telnet, it says connection refused. I am also unable to access the application. What do i miss? I do not see any exception in the ingress pod.

kubectl get ing -n test   
                 
NAME          CLASS    HOSTS   ADDRESS         PORTS   AGE
web-ingress   <none>   *       192.168.0.102   80      44m


ping 192.168.0.102

PING 192.168.0.102 (192.168.0.102) 56(84) bytes of data.
64 bytes from 192.168.0.102: icmp_seq=1 ttl=64 time=0.795 ms
64 bytes from 192.168.0.102: icmp_seq=2 ttl=64 time=0.860 ms
64 bytes from 192.168.0.102: icmp_seq=3 ttl=64 time=0.631 ms
^C
--- 192.168.0.102 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2038ms
rtt min/avg/max/mdev = 0.631/0.762/0.860/0.096 ms

telnet 192.168.0.102 80

Trying 192.168.0.102...
telnet: Unable to connect to remote host: Connection refused

kubectl get all -n ingress-nginx

shows this

NAME                                            READY   STATUS      RESTARTS   AGE
pod/ingress-nginx-admission-create-htvkh        0/1     Completed   0          99m
pod/ingress-nginx-admission-patch-cf8gj         0/1     Completed   0          99m
pod/ingress-nginx-controller-7fd7d8df56-kll4v   1/1     Running     0          99m

NAME                                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
service/ingress-nginx-controller             NodePort    10.102.220.87    <none>        80:31692/TCP,443:32736/TCP   99m
service/ingress-nginx-controller-admission   ClusterIP   10.106.159.230   <none>        443/TCP                      99m

NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ingress-nginx-controller   1/1     1            1           99m

NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/ingress-nginx-controller-7fd7d8df56   1         1         1       99m

NAME                                       COMPLETIONS   DURATION   AGE
job.batch/ingress-nginx-admission-create   1/1           7s         99m
job.batch/ingress-nginx-admission-patch    1/1           8s         99m
-- RamPrakash
kubernetes
nginx-ingress

1 Answer

7/27/2020

Answer

The IP from kubectl get ing -n test is not an externally accessible address that you should be using.

Your NGINX Ingress Controller Deployment has a Service deployed alongside it. You can use the external IP of this Service (if it has one) to hit your Ingress Controller.

Because your Service is of NodePort type (and does not show an external IP), you must address the Ingress Controller Pods through your cluster's Node IPs. You would need to track which Node the Pod is on, then find the Node's IP. Here is an example of doing this:

NODE=$(kubectl get pods -o wide | grep "ingress-nginx-controller" | awk {'print $8'})
NODE_IP=$(kubectl get nodes "$NODE" -o wide | grep Ready | awk {'print $7'})

More Info

If your cluster is managed (i.e. GKE/Azure/AWS), you can use a LoadBalancer Service to provide an external IP to hit the Ingress Controller.

-- Serge
Source: StackOverflow