Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default backend - 404 returned from nginx-controller when dns is used

a bit of background is that I have setup an Azure Kubernetes Service cluster and deployed a basic .Net Core api as a deployment object. I then deployed a nodeport service to expose the api and then deployed a nginx-controller and an ingress object to configure it. I use the IP of the ingress-controller to route the request and that works eg.http://1.2.3.4/hello-world-one/api/values. But when I replace the Ip with the generated dns, somehow the path is ignored and I get the default backend - 404 returned from the nginx controller. The expected behaviour is that the dns will resolve then the path "api/values" will be sent to my service.

Can anyone help me with this? Thanks in advance.

My deployment, service and ingress configs are below.

    apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
      name: test-deployment
      labels:
        app: test
    spec:
      replicas: 1
      selector:
         matchLabels: 
           app: test
      strategy:
        type: RollingUpdate
        rollingUpdate:
           maxUnavailable: 1
           maxSurge: 1 
      template:
        metadata:
          labels: 
            app: test
        spec:
          containers:
          - name: test-service
            image: <my-repo>.azurecr.io/testservice
            imagePullPolicy: Always
            ports:
            - name: tcp
              containerPort: 80
          imagePullSecrets:
          - name: regsecret
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: frontend
    spec:
      type: NodePort
      selector:
        app: test
      ports:
      - name: http
        port: 32768
        targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-world-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.global-static-ip-name: dev-pip-usw-qa-aks
    kubernetes.io/ingress.class: addon-http-application-routing
spec:
  rules:
  - host: hello-world-ingress.be543d4af69d4c7ca489.westus.aksapp.io
  - http:
      paths:
      - path: /
        backend:
          serviceName: frontend
          servicePort: http
      - path: /hello-world-one
        backend:
          serviceName: frontend
          servicePort: http
      - path: /hello-world-two
        backend:
          serviceName: frontend
          servicePort: http
like image 942
Paul Beliavskis Avatar asked Jan 08 '19 04:01

Paul Beliavskis


People also ask

What does default backend 404 mean?

HTTP 404 Not Found is an HTTP status code that indicates that the host has been able to communicate with the server, but the requested resource does not exist.

What is nginx default backend?

The default backend is a service which handles all URL paths and hosts the Ingress-NGINX controller doesn't understand (i.e., all the requests that are not mapped with an Ingress). Basically a default backend exposes two URLs: /healthz that returns 200. / that returns 404.

Which protocol does nginx ingress controller handle?

NGINX Ingress resources support additional protocols (TCP, UDP, and TLS Passthrough) – You can now deliver complex, non-HTTP-based services from Kubernetes using custom resources, in a simple and intuitive manner.

How do you check ingress rules?

"nginx.ingress.kubernetes.io/rewrite-target" this shows the value of an annotation on the ingress rule set. It uses the parent reference to get there. The shown value is used to determine a rewrite of the incoming path. If NOT defined, the destination service will get the same path as the source URL used.


1 Answers

pretty sure rules should look like this:

rules:
- host: hello-world-ingress.be543d4af69d4c7ca489.westus.aksapp.io
  http:
    paths:
    - path: /
      backend:
        serviceName: frontend
        servicePort: http
    - path: /hello-world-one
      backend:
        serviceName: frontend
        servicePort: http
    - path: /hello-world-two
      backend:
        serviceName: frontend
        servicePort: http

reading: https://kubernetes.io/docs/concepts/services-networking/ingress/#types-of-ingress

like image 184
4c74356b41 Avatar answered Sep 21 '22 08:09

4c74356b41