skip to Main Content

I’m pretty new to Kubernetes, I have docker for mac, not minikube.

I have the deployment file running with one pod (containing an express app) in the cluster, then i created a NodePort service.

Inside the express app i have a get request to ‘/posts’ and I want to access it from the localhost.

i have this service file here:

enter image description here

However, when i’m trying to access my localhost in the port that is given to the NodePort service,
for example localhost:30134/posts,
i get page isn’t working on Chrome.

Anyone has an idea why?

2

Answers


  1. Chosen as BEST ANSWER

    thanks for your help.

    eventually the problem was a spelling mistake in my deployment file.

    enter image description here

    At first i wrote "apps"... then i realized and change to "app" and it worked.


  2. PREMISE:

    Every node in the cluster configures itself to listen on that assigned port and to forward traffic to one of the ready endpoints associated with that Service. You’ll be able to contact the type: NodePort Service, from outside the cluster, by connecting to any node using the appropriate protocol (for example: TCP), and the appropriate port (as assigned to that Service).

    https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport

    First you should figure out what node the "posts" pod is running on.

    kubectl -n NAMESPACE get pods -owide | grep -i posts
    

    Once you figure out which node it’s running on, retrieve its INTERNAL-IP:

    kubectl get nodes -owide
    

    After that you will be able to reach the node via Browser (NODE-INTERNAL-IP:NODEPORT-PORT).

    If you absolutely want to reach the service via "localhost" name, add the entry in the /etc/hosts file.

    For example:

    echo "127.0.0.1 NODE-INTERNAL-IP" >> /etc/hosts
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search