在kubernetes中使用Nginx作为转发代理 [英] Using nginx as Forward proxy in kubernetes

查看:308
本文介绍了在kubernetes中使用Nginx作为转发代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的是kubernetes和nginx的新手.我可以通过设置入口资源将其用作反向代理,但是,我不确定如何使用它将请求从kubernetes转发到特定主机.

I am really new to kubernetes and nginx. I am able to use it as a reverse-proxy by setting up ingress resource, however, I am not sure about how should I use it to forward the request from kubernetes to a particular host.

我的情况如下: 我有一个在kubernetes容器中运行的容器,该容器使用一些参数访问外部api URL(例如www.xxx.com),但是,因为我已阻止了所有容器的传出请求,所以它无法访问该api URL.

My case is as follows: I have a container running in kubernetes pod which access an external api url (example www.xxx.com) with some parameters, however, because I have blocked the outgoing requests for all the pods, it can not access that api url.

要解决此问题,我想设置nginx代理,它将我的请求转发到实际的api url.

To solve this I want to setup nginx proxy which will forward my request to the actual api url.

我对此很陌生,并且在任何地方都没有记录到适当的步骤来实现这一目标,我真的很受困扰.我该怎么办?

Being new to this and having lack of proper steps documented anywhere to achieve this, I am really stuck. How can I do this?

推荐答案

您可以做的是定义一个指向您的外部API终结点的Service对象.通过创建名称相同的Endpoint对象和Service对象来完成此操作.

What you could do is to define a Service object that points to your external API endpoint. This is done by creating an Endpoint object and a Service object both with the same name.

https://kubernetes.io/docs/概念/服务-网络/服务/#services-无选择器

获得服务后,您可以创建一个Ingress规则,将流量转发到该服务.确保Ingress控制器可以访问您的API端点.

Once you have your service, you could create an Ingress rule that would forward the traffic to that service. Make sure that the Ingress controller can access your API endpoint.

这篇关于在kubernetes中使用Nginx作为转发代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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