2

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
Nishank
  • 159
  • 1
  • 11
  • Please provide also your `Deployemnt` and `Service` YAMLs. Are you using MetalLB? – PjoterS Aug 17 '20 at 07:15
  • updated the description with deployment and service file – Nishank Aug 17 '20 at 20:43
  • Not sure about what you are asking now. You set in your service `port: 4000` (which mean you will connect to this service by port 80) and `containerPort: 4000` which means your application is listening on port 4000). You are asking why you cannot connect using port 80 when you set everywhere 4000? Second thing could you check on what ports you application is listening `netstat -plnt`, if container wont find it use `apt update` and `apt get install net-tools` it might require `sudo`. Last thing, what happens if you will remove `- host: posts.com` from Ingress? – PjoterS Aug 20 '20 at 13:19
  • I have the exact same issue. @Nishank did you find a resolution? – McFlurriez Nov 02 '20 at 00:10

1 Answers1

2

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.

McFlurriez
  • 513
  • 6
  • 17
  • 1
    Thanks @McFlurriez for the detailed information. When I found out my same code was running on another machine I figured out something was blocking it. – Nishank Nov 03 '20 at 01:33
  • 1
    Thanks @McFlurriez you set me on the right path. I have 'World Wide Web Publishing Service' running without a problem so it can be various Services conflicting on port 80. Running 'netsh http show urlacl' displays all URL Reservations. I copied and pasted to notepad++ and searched for ':80' and found numerous but finally traced it down to 'Power BI Report Service'. Once stopped 404 error cleared. See PhoenixPan's answer, 2/17/21, at https://stackoverflow.com/questions/1430141/port-80-is-being-used-by-system-pid-4-what-is-that – Joe Oct 14 '21 at 13:33