在kubernetes上公开主机为localhost的Node js应用 [英] Expose node js app with host as localhost on kubernetes

查看:81
本文介绍了在kubernetes上公开主机为localhost的Node js应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整日都在寻找一个答案,为什么我在以负载均衡器作为服务类型的Kubernetes上运行它时,无法从互联网访问我的node js应用程序.解决方案是在节点js服务器应用程序定义中将主机从本地主机更改为0.0.0.0,但我仍然不知道为什么?

I have spent whole day looking for an answer why my node js app is not reachable from the internet when I run it on Kubernetes with loadbalancer as a service type. The solution was to change host from localhost to 0.0.0.0 in node js server app definition, but I still don’t know why?

我希望这可以节省以后的时间.

I hope this saves one’s time in the future.

推荐答案

当您说要设置主机时,我想您的意思是告诉应用程序在诸如express应用服务器.侦听所有接口,而不是仅侦听您可以使用0.0.0.0掩码(使用零来作为匹配而不是真实IP地址的掩码,可以绑定到特定地址或对所有人开放). https://stackoverflow.com/a/20778887/9705485 ).

When you say that you set the host I guess you mean what the app is told to listen on in the listen function like express app server . listen all intefaces instead of localhost only You can bind to a particular address or leave it open to all by using the 0.0.0.0 mask (the zeros function as a mask for matching rather than a true IP address - https://stackoverflow.com/a/20778887/9705485).

我想象您的应用程序在本地运行良好,并且能够使用本地主机配置从主机访问它.这是因为您的本地计算机将以符合掩码的方式访问它.您的配置实际上是说只有本地主机才能访问此应用程序.因此,当您移植到Kubernetes时,您的机器必须通过网络,而传入的连接就是您机器的外部/公共IP地址,该地址与localhost掩码不匹配.因此,要使其正常工作,您需要更改掩码以使其对所有IP开放.

I imagine you had your app running fine locally and were able to access it from your host machine with your localhost configuration. This would be because your local machine would be accessing it in a way that conforms to the mask. Your config was effectively saying only localhost can access this app. So when you ported to Kubernetes then your machine has to go over a network and the incoming connection was then your machine's external/public IP address, which then did not match the localhost mask. So to get it to work you changed the mask to make it open to all IPs.

这篇关于在kubernetes上公开主机为localhost的Node js应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆