【问题标题】:How to control vhost_shared_traffic memory K8s nginx ingress?如何控制 vhost_shared_traffic 内存 K8s nginx 入口?
【发布时间】:2020-06-21 16:41:15
【问题描述】:

背景

我们运行一个处理多个 php/lumen 微服务的 kubernetes 集群。我们开始看到应用程序 php-fpm/nginx 在其日志中报告 499 状态代码,这似乎与客户端在应用程序日志 499 时收到空白响应(curl 返回 curl: (52) Empty reply from server)相对应。

10.10.x.x - - [09/Mar/2020:18:26:46 +0000] "POST /some/path/ HTTP/1.1" 499 0 "-" "curl/7.65.3"

我的理解是,当客户端套接字不再打开/无法返回内容时,nginx 会返回 499 代码。在这种情况下,这似乎意味着在 nginx/应用程序层终止此连接之前。我们目前的配置是:

ELB -> k8s nginx 入口 -> 应用程序

所以我的想法是 ELB 或入口,因为应用程序是没有套接字可以返回的应用程序。所以我开始点击入口日志......

潜在的核心问题?

在查看入口日志时,我看到了其中不少:

2020/03/06 17:40:01 [crit] 11006#11006: ngx_slab_alloc() failed: no memory in vhost_traffic_status_zone "vhost_traffic_status"

可能的解决方案

我想如果我给 vhost_traffic_status_zone 更多内存,至少该错误会消失并继续查找下一个错误。但我似乎找不到任何可以让我控制它的 configmap 值或注释。我检查了文档:

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/

提前感谢我可能遗漏的任何见解/建议/文档!

【问题讨论】:

  • 你见过this comment吗?
  • 所以这肯定会遇到同样的问题,但我无法直接访问 nginx conf,而是创建 k8s nginx 入口对象的掌舵图——所以我可以控制入口的注释,并控制入口命名空间的配置映射值。根据问题,我没有看到任何允许我控制链接提到的相同 nginx 配置选项的注释/配置映射。但我真的希望有一个!
  • 您使用的是哪个版本的控制器?

标签: nginx kubernetes kubernetes-ingress


【解决方案1】:

这是查找如何在入口控制器中修改 nginx.conf 的标准方法。之后,我将链接一些关于您应该为该区域提供多少内存的建议的信息。

首先通过检查部署上的映像版本来获取入口控制器版本 kubectl -n <namespace> get deployment <deployment-name> | grep 'image:'

从那里,您可以从以下 URL 检索您的版本的代码。在下文中,我将使用 0.10.2 版本。 https://github.com/kubernetes/ingress-nginx/releases/tag/nginx-0.10.2

nginx.conf 模板可以在代码中的 rootfs/etc/nginx/template/nginx.tmpl 或 pod 上的 /etc/nginx/template/nginx.tmpl 中找到。这可以用于感兴趣的行。以我为例,我们在 nginx.tmpl 中找到以下行

vhost_traffic_status_zone shared:vhost_traffic_status:{{ $cfg.VtsStatusZoneSize }};

这为我们提供了在代码中查找的配置变量。我们对 VtsStatusZoneSize 的下一个 grep 将我们带到 internal/ingress/controller/config/config.go 中的行

    // Description: Sets parameters for a shared memory zone that will keep states for various keys. The cache is shared between all worker processe
    // https://github.com/vozlt/nginx-module-vts#vhost_traffic_status_zone
    // Default value is 10m
    VtsStatusZoneSize string `json:"vts-status-zone-size,omitempty"

这为我们提供了要添加到配置映射“ingress-nginx-ingress-controller”的键“vts-status-zone-size”。当前值可以在 /etc/nginx/nginx.conf 的 pod 上呈现的 nginx.conf 模板中找到。

当涉及到您可能想要设置区域的大小时,此处的文档建议将其设置为 2*usedSize:

如果error_log中打印消息("ngx_slab_alloc() failed: no memory in vhost_traffic_status_zone"),则增加到大于(usedSize * 2)。

https://github.com/vozlt/nginx-module-vts#vhost_traffic_status_zone

“usedSize”可以通过点击 nginx 的统计页面或通过 JSON 端点找到。这是获取统计数据的 JSON 版本的请求,如果您有 jq 值的路径:curl http://localhost:18080/nginx_status/format/json 2> /dev/null | jq .sharedZones.usedSize

希望这会有所帮助。

【讨论】:

  • 一个小提示:如果您的 Ingress Controller 由部署控制,请确保您有足够的副本来平均路由流量。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-12
  • 2018-07-17
  • 1970-01-01
  • 2021-03-04
  • 1970-01-01
  • 2021-05-16
  • 1970-01-01
相关资源
最近更新 更多