How do I get the external IP of my NodePort using LKE?

Linode Staff

I have deployed Nginx and assigned a NodePort service to port forward from that pods. But where do I get the external IP from, and how do I access my deployed Nginx server in Kubernetes from my browser?

This is the command I used to set this up, but I'm unable to get the external IP.

kubectl expose pods nginx-pods --type=NodePort --port=8000 --target-port=80 --name myfirstservice1

1 Reply

You should be able to access your nginx page using your IP:NodePort (where your IP is any of your cluster node's public IP address). To get your NodePort, run:

kubectl get svc myfirstservice1
NAME              TYPE       CLUSTER-IP    EXTERNAL-IP    PORT(S)          AGE
myfirstservice1   NodePort   10.128.5.30   192.0.2.0      8000:30761/TCP   9m30s

Your NodePort would be after the 8000. Mine is 30761.

You can then visit your nginx page at any of your cluster node's public IP addresses, followed by the NodePort.

You can see your Linode's IPs by looking at your Node Pool in Cloud Manager, or by checking the EXTERNAL-IP column when running:

 kubectl get nodes -owide

Then once you visit your external-ip at port 30761 (in my case), your nginx root will be visible.

For example:

http://192.0.2.0:30761/

To avoid needing to hit a specific port within the default range of 30000-32767 (See: Kubernetes - Type NodePort on this), you can use the LoadBalancer service instead. However, this will create a NodeBalancer on your account at $10/mo, so there would be an added charge for this.

To do that, you could run this instead:

kubectl expose deployment mysecondservice --port=80 --type=LoadBalancer

To get your NodeBalancer's IP address, you'd run kubectl get svc mysecondservice. Then you can hit your IP directly (or your domain if you've configured DNS) without needing to use your NodePort.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct