ingress can not get the default http backend

Viewed 13172

The ingress I config to run with the controller ingress-nginx.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  tls:
  - hosts:
    - XXX.XX.com
    secretName: app-tls
  rules:
  - host: XXX.XX.com
    http:
      paths:
      - path: /my-api(/|$)(.*)
        backend:
          serviceName: app
          servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: my-api
spec:
  selector:
    app: my-api
  ports:
  - name: app
    port: 3000
    targetPort: 3000

I can run the api locally curl localIP:3000/testapi, but it can not run remotely.

# kubectl describe ingress app-ingress
Name:             app-ingress
Namespace:        default
Address:          XX.XX.XX.XX
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
TLS:
  app-tls terminates www.daichenchen.cn
Rules:
  Host                Path  Backends
  ----                ----  --------
  XXX.XX.com
                      /my-api(/|$)(.*)   app:80 (<error: endpoints "app" not found>)

I already succeed install the ingress-nginx and all the pod work without error.

2 Answers

Your defined serviceName in Ingress rules and Service should be same.

Like this :

...
  rules:
  - host: XXX.XX.com
    http:
      paths:
      - path: /my-api(/|$)(.*)
        backend:
          serviceName: app
          servicePort: 80
apiVersion: v1
kind: Service
metadata:
  name: app
spec:
  selector:
    app: my-api
  ports:
  - name: app
    port: 3000
    targetPort: 3000

If Ingress and the Service is in different namespace, you can also add the service name to the ingress rule. In this case you need to use dns name for service <service-name>.<namespace>.

For example:

  rules:
  - host: example.com
    http:
      paths:
      - path: /my-api
        backend:
          serviceName: test-service.test-namespace
          servicePort: 80
apiVersion: v1
kind: Service
metadata:
  name: test-service
  namespace: test-namespace

The way ingress controller finds out Endpoints of a service is it searches for a kubernetes service with the serviceName provided in the ingress resource in the namespace where you have created the ingress resource. If there is no kubernetes service with serviceName found you get endpoints not found.

The Endpoints of the service contains the IPs of pods behind the kubernetes service.

So in your case either the kubernetes service does not exist or it's in a different namespace than where ingress resource is created.

Some variant of nginx ingress controller does not support default backend and for this it's expected to have the error: endpoints "default-http-backend" not found

Another variant of nginx ingress controller supports default backend.

Double check which variant of nginx ingress controller you installed

Related