Connection refused trying to connect via ingress interface

1/11/2022

Using Calico as CNI and CRI-O. DNS settings properly configured. Installed NGINX ingress controller via official documentation page of NGINX using helm. Set replicaset to 2 when installing.

After that used this file for creating 3 objects: Deployment, Service for exposing web server and Ingress.

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  name: test-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-service-pod
  template:
    metadata:
      labels:
        app: nginx-service-pod
    spec:
      containers:
      - image: nginx 
        name: test-nginx
---
apiVersion: v1
kind: Service
metadata:
   name: nginx-service
spec:
   type: ClusterIP
   selector:
      app: nginx-service-pod
   ports:
      - port: 80
        targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
spec:
  rules:
  - host: k8s.example.com
    http:
      paths:
      - path: /test
        pathType: Prefix
        backend:
          service:
            name: nginx-service
            port:
              number: 80
...

Tried to test deployment service by curling it and it is working correct:

# curl http://10.103.88.163
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

But when I'm trying to curl Ingress getting error:

# curl http://k8s.example.com/test
curl: (7) Failed to connect to k8s.example.com port 80: Connection refused

Why this is happening? Because as I see there is no misconfig in the objects configuration.

-- Just
kubernetes
kubernetes-helm
kubernetes-ingress
nginx-ingress

1 Answer

1/31/2022

This problem should be resolved by adding

spec: 
  template:
    spec:
      hostNetwork: true

to the ingress controller yaml manifest. For more please check this github issue and this answer.

-- Mikołaj Głodziak
Source: StackOverflow