在Kubernetes入口Ngnix中编辑max_conns吗? [英] Edit max_conns in Kubernetes ingress Ngnix?

查看:204
本文介绍了在Kubernetes入口Ngnix中编辑max_conns吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试限制Nginx入口中与服务器的并发连接数.

Im trying to limit the number of concurrent connection to servers in my Nginx ingress.

Ngnix入口支持max_conns吗?我该如何编辑或添加它?

is max_conns supported in Ngnix ingress? how can i edit or add it?

max_conns =数量 限制到代理服务器的同时活动连接的最大数量(1.11.5).默认值为零,表示没有限制.如果服务器组未驻留在共享内存中,则此限制在每个工作进程中均有效.

max_conns=number limits the maximum number of simultaneous active connections to the proxied server (1.11.5). Default value is zero, meaning there is no limit. If the server group does not reside in the shared memory, the limitation works per each worker process.

http://nginx.org/en/docs/http/ngx_http_upstream_module .html#upstream

使用max_conn的Nginx conf的示例

exmple of an Nginx conf using max_conn

upstream backend {
server backend1.example.com  max_conns=3;
server backend2.example.com;}

谢谢

推荐答案

因此,要添加max_conns(或入口configmap不支持的任何其他参数),需要做的是更改模板.

So, what needed to be done in order to add max_conns (or any other parameter that is not supported by the ingress configmap) - is to change the template.

像这样更改模板/etc/nginx/template/nginx.tmpl:

changing the template /etc/nginx/template/nginx.tmpl like this:

upstream {{ $upstream.Name }} {
    # Load balance algorithm; empty for round robin, which is the default
    {{ if ne $cfg.LoadBalanceAlgorithm "round_robin" }}
    {{ $cfg.LoadBalanceAlgorithm }};
    {{ end }}

    {{ if $upstream.UpstreamHashBy }}
    hash {{ $upstream.UpstreamHashBy }} consistent;
    {{ end }}

    {{ if (gt $cfg.UpstreamKeepaliveConnections 0) }}
    keepalive {{ $cfg.UpstreamKeepaliveConnections }};
    {{ end }}

    {{ range $server := $upstream.Endpoints }}server {{ $server.Address | formatIP }}:{{ $server.Port }} max_fails={{ $server.MaxFails }} fail_timeout={{ $server.FailTimeout }} max_conns=1;
    {{ end }}
}

(您可以从pod nginx-ingress-controller获取完整文件,只需在pod上运行bash并对其进行分类即可) 会成功的 现在使用本地nginx.tmpl创建一个configmap:

(you can get the full file from the pod nginx-ingress-controller, just run bash on the pod and cat it) will do the trick. now create a configmap with the local nginx.tmpl:

kubectl create configmap nginx-template --from-file=nginx.tmpl=/localpath/nginx.tmpl

,然后使用此yaml将卷安装到部署中:

and then mount a volume to the deployment with this yaml:

        volumeMounts:
      - mountPath: /etc/nginx/template
        name: nginx-template-volume
        readOnly: true
  volumes:
    - name: nginx-template-volume
      configMap:
        name: nginx-template
        items:
        - key: nginx.tmpl
          path: nginx.tmpl

  • 我需要手动重新启动NGINX入口,但是由于没有部署(我想这是因为我在minikube上),所以我编辑了Re​​plicationController
  • 这篇关于在Kubernetes入口Ngnix中编辑max_conns吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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