如何使用Nginx Ingress控制器在每个Pod中仅允许一个连接 [英] How to allow only one connection per pod using nginx ingress controller
问题描述
我的Kubernetes集群使用一个copySet来运行N个相似的Pod.由于资源限制,每个pod只能处理一个websocket连接.我的Kubernetes使用Nginx入口控制器.
My Kubernetes cluster uses a replicaSet to run N similar pods. Each pod can only handles one websocket connection du to resource limitations. My Kubernetes uses a nginx ingress controller.
有没有办法使Nginx每个Pod只调度一个传入的Websocket连接,并且在缺少可用Pod的情况下,拒绝传入的连接?
Is there any way to make nginx dispatch only one incoming websocket connection per pod and in case of lack of available pods, refuses the incoming connection ?
推荐答案
我对Kubernetes Nginx入口设置不太熟悉,但是假设它公开了一些Nginx配置选项来设置服务器组,在server
函数中有一个名为max_conns
的参数,该参数可让您限制与给定服务器的连接数.假设入口控制器中存在映射,则应该有可能为要创建的每个服务器设置max_conns=1
并将其添加到后台的Nginx配置中.
I'm not super familiar with the Kubernetes Nginx ingress setup, but assuming it exposes some of the Nginx configuration options for setting up groups of servers, in the server
function there's a parameter called max_conns
that will let you limit the number of connections to a given server. Assuming there's a mapping in the ingress controller, it should be possible to set max_conns=1
for each server that's getting created and added to the Nginx configuration under the hood.
http://nginx.org/en/docs/http/ngx_http_upstream_module .html#server
一些粗略的研究,看来这确实是可能的.看起来您可以根据此处的参数主列表在ConfigMap
中将其指定为nginx.org/max-conns
:
a little cursory research and it looks like this is indeed possible. It looks like you can specify this in a ConfigMap
as nginx.org/max-conns
according to the master list of parameters here: https://github.com/nginxinc/kubernetes-ingress/blob/master/docs/configmap-and-annotations.md
这篇关于如何使用Nginx Ingress控制器在每个Pod中仅允许一个连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!