Summary
I have hosted one of my websites on kubernetes and am happy with it … except with one thing: how I can access it. My local IP address is 10.0.0.21
. If I use localhost
or 127.0.0.1
, it works. But if I use my local IP address, I cannot access it.
Sound similar. Here is how to solve it.
TL;DR
You must pay attention to the interface your website is listening on.
if you run the website with grunt, make sure that you use 0.0.0.0
instead of localhost
.
IMPORTANT NOTICE
Most of the application come configured to listen on
localhost
only for security reasons. It avoids exposing a potentially unsecure server outside of the server it is running on. It allows the administrator to test locally the application before releasing it to the rest of the world.
My setup
I have my website installed on kubernetes.
To run it, I use the command grunt serve
.
The command starts my website on the port 9000
.
The problem
Here are the urls that I use to access it (If my computer is connected to my home network):
- http://localhost:9000/ : works okay.
- http://127.0.0.1:9000/ : works okay too.
- http://10.0.0.21:9000/ : fail to connect
If my computer is connected to other networks, all the three urls work well.
The solution
The issue is coming from the interface the application is running on.
If you start the application using localhost
interface it will be available on the server only.
If you start the application using 0.0.0.0
interface, it will be available on all the available interfaces, hence your local IP address.
To solve the issue:
- Stop the application
- Update the configuration (start the application using the
0.0.0.0
) - Start the application using the same command as before
grunt serve
-
Connect to the application using it’s local ip address
http://10.0.0.21:9000/
Conclusion
I hope this solution will help you in your journey. Contact us if you need help.