Kubernetes Nginx Ingress Controller on Service without Selector

5/5/2018

I'm trying to expose a Service that has no Selector on Ingress (with Kubernetes official Nginx Controller).

The Service without the Selector works fine when I set it as NodePort, and it uses the Endpoint that I define manually.

However, once I setup an Ingress resource pointing to this service I cannot get it working.

This is what Nginx complains about:

connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.99.1, server: example, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8181/", host: "example"
connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.99.1, server: example, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8181/favicon.ico", host: "example", referrer: "http://example/"

And these are my Service and Ingress resources:

apiVersion: v1
kind: Service
metadata:
  name: example
  labels:
    app: example
spec:
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: http


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example
  labels:
    app: example
spec:
  rules:
    - host: myhostname
      http:
        paths:
          - path: /
            backend:
              serviceName: example
              servicePort: http

Note: I'm manually editing the Endpoint for the Service after the deployment. But I don't see how this could make any difference.

Any ideas?


EDIT:

I've added an additional Service with a Selector, running side by side with the other one that has no Selector.

When I have the Ingress pointing to the one with no Selector, this is the upstream on Nginx:

upstream default-old-joey-app.example-no-selector {
    least_conn;

    server 127.0.0.1:8181 max_fails=1 fail_timeout=10s;

}

As soon as I switch the Ingress resource to point to the Service with Selector, Nginx's updstream is updated to:

upstream default-old-joey-app.example-with-selector {
    least_conn;

    server 172.17.0.5:8080 max_fails=1 fail_timeout=10s;

}

Could this be an issue with the Ingress Controller?

-- halfwarp
kubernetes
kubernetes-ingress

1 Answer

5/8/2018

In your Ingress you are indicating http as the servicePort in the backend, while your service is listening to port 8080.

Change it like this and it should work:

backend:
  serviceName: example
  servicePort: 8080
-- whites11
Source: StackOverflow