skip to Main Content

I am trying to learn .NET Microservice. I have been following a great tutorial on Youtube (Time: 4:44:55, Adding An API Gateway). Everything worked well until NGINX Ingress came into the picture. I pasted the same YAML file from the GitHub account of the trainer I doubled checked all the things but couldn’t find anything:

I can see all the pods and services are working fine:

enter image description here

enter image description here

I updated my host file.

enter image description here

What did I miss?

URL, I am using: http://acme.com/api/platforms/

Error: HTTP Error 404. The requested resource is not found.

The output of the Ingress YAML:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{"kubernetes.io/ingress.class":"nginx","nginx.ingress.kubernetes.io/use-regex":"true"},"name":"ingress-srv","namespace":"default"},"spec":{"rules":[{"host":"acme.com","http":{"paths":[{"backend":{"service":{"name":"platforms-clusterip-srv","port":{"number":80}}},"path":"/api/platforms","pathType":"Prefix"},{"backend":{"service":{"name":"commands-clusterip-srv","port":{"number":80}}},"path":"/api/c/platforms","pathType":"Prefix"}]}}]}}
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
  creationTimestamp: "2021-09-18T00:12:41Z"
  generation: 1
  name: ingress-srv
  namespace: default
  resourceVersion: "2274742"
  uid: a7376202-8b1b-4f1a-a42f-08de5f602192
spec:
  rules:
  - host: acme.com
    http:
      paths:
      - backend:
          service:
            name: platforms-clusterip-srv
            port:
              number: 80
        path: /api/platforms
        pathType: Prefix
      - backend:
          service:
            name: commands-clusterip-srv
            port:
              number: 80
        path: /api/c/platforms
        pathType: Prefix
status:
  loadBalancer:
    ingress:
    - hostname: localhost

Services:
enter image description here

UPDATE: Tried below commands and got some new information:

enter image description here

UPDATE: Result of

Kubectl get pods –namespace=ingress-nginx

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    First of all, Thank you Harsh for your precious time. I tried all the things but no error was found.

    It was really a miracle that I am able to resolve it issue on HTTPS. I am able to access "https://acme.com/api/platforms". But still, HTTP is giving me the same error. However, I am fine with HTTPS


  2. Try removing the regex annotation from th ingress

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        kubernetes.io/ingress.class: nginx
      name: ingress-srv
      namespace: default
    spec:
      rules:
      - host: acme.com
        http:
          paths:
          - backend:
              service:
                name: platforms-clusterip-srv
                port:
                  number: 80
            path: /api/platforms
            pathType: Prefix
          - backend:
              service:
                name: commands-clusterip-srv
                port:
                  number: 80
            path: /api/c/platforms
            pathType: Prefix
    

    or just try this nginx.ingress.kubernetes.io/rewrite-target: /

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: minimal-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - host: acme.com
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: commands-clusterip-srv
                port:
                  number: 80
    

    in above ingress, all requests will go to service commands-clusterip-srv so from browser side you pass anything either /api or /api/c ingress will route the traffic to that service if your host is acme.com

    Error 404 clearly means there is some issue with your Nginx configuration path is not matching or host issue, Nginx not able to find upstream or target so it throws 404.

    Update

    Try adding IP and entry into the host file for

    192.168.1.28 acme.com
    

    i am not sure you have used the IP POD to curl ideally you should me using the acme.com as you can to access the data.

    also hope you service, deployment and ingress are in same namespace.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search