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

1/8/2019

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
-- Paul Beliavskis
azure-aks
kubernetes
nginx-ingress

1 Answer

1/8/2019

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

-- 4c74356b41
Source: StackOverflow