简体   繁体   English

向外部服务器请求时如何代理 Kubernetes 容器中的 IP 地址

[英]how to proxy IP address in Kubernetes container when requesting to foreign server

I am trying to make a GET request to a foreign server.我正在尝试向外部服务器发出 GET 请求。 But the foreign server requires our IP address for security purposes.但是出于安全考虑,国外服务器需要我们的 IP 地址。

Now the problem is I am running my app inside Kubernetes' pod with three nodes.现在的问题是我在 Kubernetes 的 pod 中运行我的应用程序,其中包含三个节点。 When I send the request, it takes the IP address of one of the kubernetes nodes.当我发送请求时,它需要 kubernetes 节点之一的 IP 地址。 I could add static IP addresses to all my nodes.我可以将 static IP 地址添加到我的所有节点。 But from what I have learned, best practice is to only release the Gateway(ingress) IP address to the outside world.但据我所知,最好的做法是只向外界发布网关(入口)IP 地址。 Everything else should be hidden.其他一切都应该隐藏起来。

So I tried to proxy my axios request like this:所以我尝试像这样代理我的 axios 请求:

var res = await axios.get('https://someapi.com', {
    proxy: {
        host: 'ingressIP', //static ip
        port: 80
    }
});

But the request still returns an error saying that the IP is not allowed.但是请求仍然返回一个错误,说 IP 是不允许的。 It returned the IP address of the kubernetes node, where my POD was in.它返回了我的 POD 所在的 kubernetes 节点的 IP 地址。

I am not sure, that you will be able to pass your traffic through ingress somehow.我不确定您是否能够以某种方式通过入口传递您的流量。

We also had the same problem.我们也有同样的问题。 We needed to send requests to a third-party server from a specific IP-address.我们需要从特定 IP 地址向第三方服务器发送请求。

But we solved this a bit different, we just created a new small server with static IP, installed Squid proxy server there and configured our applications to use Squid server as an HTTP forward proxy.但是我们解决了这个问题有点不同,我们刚刚使用 static IP 创建了一个新的小型服务器,在那里安装了Squid代理服务器并将我们的应用程序配置为使用 Squid 服务器作为 Z293C9EA246FF9985DC6F62A650F79 转发代理。

Squid has a lot of features, and IMO is quite bloated for such a simple use-case; Squid 有很多功能,IMO 对于这样一个简单的用例来说相当臃肿; I'd suggest something more lightweight, like tinyproxy (docker image here ).我建议使用更轻量级的东西,例如tinyproxy此处为 docker image)。 So what you can do is create a Deployment using that image, pin it to a specific node (the one with the IP that the 3rd party API allows) using nodeSelector , create a Service pointing to it, and use that as a proxy in your requests.因此,您可以做的是使用该映像创建一个Deployment ,使用 nodeSelector 将其固定到特定节点(第 3 方 API 允许的具有IP的节点),创建一个指向它的Service ,并将其用作您的代理要求。 There's one drawback to this approach, though - you just added a(nother) single point of failure to your infrastructure.但是,这种方法有一个缺点——您只是在基础架构中添加了一个(另一个)单点故障。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 配置NGINX时哪个IP地址进入proxy_pass - Which IP address goes in proxy_pass when configuring NGINX 在节点前使用Nginx服务器作为代理时如何获取客户端真实IP - How get client real IP when using nginx server in front of node as proxy Docker-Windows上容器的IP地址 - Docker - IP address of container on Windows 如何在nodejs项目中获取aws ecs容器ip地址 - How to fetch aws ecs container ip address in nodejs project 在带有 Nest.js 的 Node 中,当客户端和服务器应用程序分开时,如何获取用户的 IP 地址 - how to I get a user's IP address when separate client and server apps, in Node with Nest.js 在运行带端口转发的容器时,没有从node.js代码获取docker容器的IP地址 - Not getting the IP address of the docker container from node.js code when run the container with port forwarding Express js Invalid ip address in morgan logs when using nginx 反向代理 - Express js Invalid ip address in morgan logs when using nginx reverse proxy 如何在NodeJS中获取DNS服务器IP地址 - How Do I Get DNS Server IP Address In NodeJS 如何在其他IP地址启动Express 4.x Server? - How to start Express 4.x Server at Different IP Address? 如何在阿波罗订阅服务器上获取客户端 IP 地址? - How to get client ip address on an apollo subscriptions server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM