Nishank
Nishank

Reputation: 159

404 page not found when kubernetes ingress-nginx is run on docker windows

I am running docker on windows machine and trying to access the http://posts.com/posts as I get HTTP Error 404.0 - Not Found.

windows host config file has been configured correctly

127.0.0.1 posts.com

as I can browse to http://posts.com

I can also access using the port number http://posts.com:31783/posts.

I am not sure why I cannot access over port 80.

following are the logs from kubernetes

enter image description here

enter image description here

and ingress configuration

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata: 
    name: ingress-srv
    annotations: 
        kubernetes.io/ingress.class: nginx
spec:
  rules: 
    - host: posts.com
      http:
        paths:
          - path: /posts
            backend:
              serviceName: posts-clusterip-srv            
              servicePort: 4000

Deployment and Service file

apiVersion: apps/v1
kind: Deployment
metadata:
    name: posts-depl
spec:
    replicas: 1
    selector:
        matchLabels:
            app: posts
    template:
        metadata:
            labels:
                app: posts
        spec:
            containers:
                - name: posts
                  image: nishank/posts:latest
---
apiVersion: v1
kind: Service
metadata:
    name: posts-clusterip-srv
spec:
    type: ClusterIP
    selector:
        app: posts
    ports:
        - name: posts
          protocol: TCP
          port: 4000
          targetPort: 4000

Upvotes: 2

Views: 8165

Answers (1)

McFlurriez
McFlurriez

Reputation: 591

Alright I finally have a solution to this issue.

First of all, this question is in reference to Stephen Grider's Microservices with Node JS and React course. I know this because the service/configuration attempted is straight from the course content.

There is something running on your Windows PC that is already using port 80, and that is why you receive a 404. To find out what process is doing this, first run the following inside a powershell / windows terminal instance:

netstat -ano | findstr ":80" | findstr "LISTENING"

You will see something like the following:

❯ netstat -ano | findstr ":80" | findstr "LISTENING"
TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       13056
TCP    [::]:80                [::]:0                 LISTENING       13056
TCP    [::1]:80               [::]:0                 LISTENING       16852

Once you note the PID listening on port 80, open up Task Manager using "Ctrl+Alt+Delete" and go to the Details tab. Sort by PID and find the process that you found listening to port 80. When I had the issue, the PID was 4.

Sometimes the process name is distinct, and other times it will just be called "System". So regardless of the name, right click the name and click "open file location".

If you are taken to "ntoskrnl.exe", then the guilty culprit is most likely the "World Wide Web Publishing Service". You can check this by typing "Services" in the Windows search bar, opening Services, and finding it on the list. If it is running, go ahead and stop it.

If that was not the case, there are other services/processes that can get in the way as well. The Stackoverflow here has a bunch of responses from other people with other processes sitting on port 80.

Once you have tackled that, apply your service again using:

kubectl apply -f ingress-srv.yaml

and you should be good to go.

Upvotes: 3

Related Questions