Monday, September 13, 2021

How to fix "HTTP Error 404.0 - Not Found" in Kubernetes ingress-nginx services?

i had setup the kubernetes Ingress with ingress-nginx with the following code, in my local machine,

which will direct the traffic to the backend service in kubernetes

apiVersionnetworking.k8s.io/v1
kindIngress
metadata:
  nameingress-srv
  annotations:
    kubernetes.io/ingress.classnginx
    nginx.ingress.kubernetes.io/use-regex"true"
spec:
  rules:
    - hostacme.com
      http:
        paths:
          - path/api/platforms
            pathTypePrefix
            backend:
              service:
                nameplatformservice-clusterip-srv
                port:
                  number80
          - path/api/c/platforms
            pathTypePrefix
            backend:
              service:
                namecommandservice-clusterip-srv
                port:
                  number80

after the setup is complete. i try to browse to the platform service web api which is hosted in the backend server.

http://acme.com/api/platforms/  but the error comes up immediately, which indicated that 

  • The directory or file specified does not exist on the Web server.

since the directory was not hosted in the IIS, it had been deployed to the pods in the kuberentes


As we manipulate the kubernetes in the local environment, we can check what process is using the port 80

C:\code\dotnet-microservices\k8s>netstat -ano | findstr ":80" | findstr "LISTENING"

  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4

  TCP    0.0.0.0:8081           0.0.0.0:0              LISTENING       4

  TCP    [::]:80                [::]:0                 LISTENING       4

  TCP    [::]:8081              [::]:0                 LISTENING       4


the PID 4 represnet that the port 80 had been assigned to IIS local host.  we should stop the World Wide Web Publishing Service, in order to release the port 80 for Kubernetes services. 



after I stop the World Wide Web Publishing Service, the we can see that port 80 had been assigned to different processes.

C:\code\dotnet-microservices\k8s>netstat -ano | findstr ":80" | findstr "LISTENING"

  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       3440

  TCP    [::]:80                [::]:0                 LISTENING       3440

  TCP    [::1]:80               [::]:0                 LISTENING       16096

Now we should be able to access the web api host in the kubernetes.

[{"id":1,"name":"dotnet","cost":"free","publisher":"Microsoft"},{"id":2,"name":"SQL Server Express","cost":"free","publisher":"Microsoft"},{"id":3,"name":"Kubernetes","cost":"free","publisher":"Cloud Native Computer Foundation"}]







No comments:

Post a Comment