'Error: getaddrinfo ENOTFOUND ingress-nginx.ingress-nginx-controller.svc.cluster.local

I am working with NextJS and I need for it to know when it's making a request on the server or on the browser. To do it on the server-side because I am building this inside a microservices architecture, I need to obtain the service name and namespace of the service to complete the url like so http://SERVICENAME.NAMESPACE.svc.cluster.local.

So in my terminal I printed out all my different namespaces like so:

$kubectl get namespace

NAME              STATUS   AGE
default           Active   9d
ingress-nginx     Active   9d
kube-node-lease   Active   9d
kube-public       Active   9d
kube-system       Active   9d

So ingress-nginx is what I am looking for. Then I ran:

$kubectl get services -n ingress-nginx

NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   10.100.129.149   localhost     80:30463/TCP,443:31399/TCP   9d
ingress-nginx-controller-admission   ClusterIP      10.111.40.184    <none>        443/TCP                      9d

So to my understanding ingress-nginx-controller is the name of my service.

So I am making the request to http://ingress-nginx.ingress-nginx-controller.svc.cluster.local/api/users/currentuser, but I also had to specify a host like so:

LandingPage.getInitialProps = async () => {
  if (typeof window === "undefined") {
    const { data } = await axios.get(
      "http://ingress-nginx.ingress-nginx-controller.svc.cluster.local/api/users/currentuser",
      {
        headers: {
          Host: "ticketing.dev",
        },
      }
    );

    return data;
  } else {
    const { data } = await axios.get("/api/users/currentuser");

    return data;
  }
};

but when I make the request I am still getting this printing out on the browser:

enter image description here

I pulled kubectl logs and everything is 200:

192.168.65.3 - - [06/Nov/2020:01:30:15 +0000] "GET /_next/static/chunks/pages/_app.js?ts=1604626215582 HTTP/2.0" 200 600778 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 51 0.131 [default-client-srv-3000] [] 10.1.0.244:3000 601240 0.132 200 406761022b9aad1a8cd45b9574f3082c
192.168.65.3 - - [06/Nov/2020:01:30:15 +0000] "GET /_next/static/chunks/main.js?ts=1604626215582 HTTP/2.0" 200 1141017 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 46 0.259 [default-client-srv-3000] [] 10.1.0.244:3000 1141886 0.258 200 da2d882e400bebe57a8ce403acd55c8b
192.168.65.3 - - [06/Nov/2020:01:30:16 +0000] "GET /_next/static/chunks/0.js HTTP/2.0" 200 1578 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 32 0.003 [default-client-srv-3000] [] 10.1.0.244:3000 1595 0.003 200 264ab274cf006691d92b1f03f05ffbca
192.168.65.3 - - [06/Nov/2020:01:30:27 +0000] "GET /_next/webpack-hmr?page=/ HTTP/2.0" 200 1499 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 34 11.495 [default-client-srv-3000] [] 10.1.0.244:3000 1543 11.495 200 99420f1d80b74b84c0cb42ead9981d43

What am I missing? I don't think the issue is in the ingress-srv.yml file:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
    - host: ticketing.dev
      http:
        paths:
          - path: /api/users/?(.*)
            backend:
              serviceName: auth-srv
              servicePort: 3000
          - path: /?(.*)
            backend:
              serviceName: client-srv
              servicePort: 3000


Solution 1:[1]

Base on URL of accessing the service:

http://SERVICENAME.NAMESPACE.svc.cluster.local 

so it should be

http://ingress-nginx-controller.ingress-nginx.svc.cluster.local

Solution 2:[2]

With minikube sometimes the nginx controller is not exposed.

$ kubectl expose deployment ingress-nginx-controller --target-port=80 --type=NodePort -n kube-system

Solution 3:[3]

If nothing works try using the cluser-ip of the service

$ kubectl get services -n ingress-nginx

NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             NodePort       10.100.129.149   localhost     80:30463/TCP,443:31399/TCP   9d
ingress-nginx-controller-admission   ClusterIP      10.111.40.184    <none>        443/TCP                      9d

index.js

const { data } = await axios.get(
      "http://10.100.129.149/api/users/currentuser",
      {
        headers: {
          Host: "ticketing.dev",
        },
      }
    );

OR

  # This worked for me
  const { data } = await axios.get(
          "http://ingress-nginx-controller.ingress-nginx",
          {
            headers: {
              Host: "ticketing.dev",
            },
          }
        );



export default Landing;

And carry on with the tutorial

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thanh Nguyen Van
Solution 2 Rafiq
Solution 3