4

I have an ingress deployed in a k8s cluster in VMware. The issue is that the DNS responds inside the container:

[root@k8s-cluster ~]# kubectl exec -it -n test ingress-nginx-controller-848bfcb64d-n796z  -- curl localhost/banana -H 'Host: k8s-cluster.lab.buch.int'
banana

But if I try from the cluster:

[root@k8s-cluster ~]# curl localhost/banana
curl: (7) Failed connect to localhost:80; Connection refused

It doesn't work even if I use the DNS instead of localhost or the IP assigned by metallb to the ingress controller.

[root@k8s-cluster ~]# kubectl get services
NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
apple-service                        ClusterIP      10.97.109.66     <none>        5678/TCP                     6d15h
banana-service                       ClusterIP      10.110.129.29    <none>        5678/TCP                     6d15h
ingress-nginx-controller             LoadBalancer   10.99.151.233    10.133.2.21   80:31981/TCP,443:30293/TCP   6d15h
ingress-nginx-controller-admission   ClusterIP      10.108.116.127   <none>        443/TCP                      6d15h
[root@k8s-cluster ~]# kubectl describe ing
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Name:             example-ingress
Namespace:        test
Address:          10.133.65.148
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                            Path  Backends
  ----                            ----  --------
  k8s-cluster.lab.buch.int
                                  /apple(/|$)(.*)    apple-service:5678 (192.168.86.184:5678)
                                  /banana(/|$)(.*)   banana-service:5678 (192.168.76.157:5678)
Annotations:                      kubernetes.io/ingress.class: nginx
                                  nginx.ingress.kubernetes.io/rewrite-target: /$2
Events:                           <none>

If I curl the external ip assigned by metallb: 10.133.2.21

[root@k8s-cluster ~]# curl 10.133.2.21
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>

So, it means that the nginx works in a some way, but if I try to curl 10.133.2.21/banana or 10.133.2.21/apple it doesn't work.

Any ideas?

DobreMihaela
  • 174
  • 1
  • 10
  • How did you deploy `Nginx Ingress controller`? What K8s version are you using? It's Minikube or Kubeadm? Can you provide logs form Ingress Controller? – PjoterS Jan 05 '21 at 09:53

1 Answers1

0

In your Ingress configuration, you specified k8s-cluster.lab.buch.int host, therefore you can reach apple and banana services using this specific hostname:

curl k8s-cluster.lab.buch.int/apple

and

curl k8s-cluster.lab.buch.int/banana

Solution

If you change Ingress host to * (all hosts) which is default configuration, or remove this field from your YAML.

...
rules:
- host: "k8s-cluster.lab.buch.int" ### Here you can change to "*" or remove this field
  http:
    paths:
    - path: "/apple(/|$)(.*)"
      backend:
...

With above change you will be able to reach your services using LoadBalancer IP address:

$ curl 10.133.2.21/apple

and

$ curl 10.133.2.21/banana

As you can read in Kubernetes Ingress rules docs:

Both the host and path must match the content of an incoming request before the load balancer directs traffic to the referenced Service.

In addition, 404 Not Found when you are trying to $ curl 10.133.2.21 and $ curl k8s-cluster.lab.buch.int is expected behavior, as you didn't set default-backend

Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)

PjoterS
  • 12,841
  • 1
  • 22
  • 54