一个k8s 集群采用的是kong作为ingress controller,查日志的时候发现kong有一个warning
a client request body is buffered to a temporary file

问题分析

通过kong的admin api可以看到,与之相关的是nginx的一个配置
client_body_buffer_size: 8k
这个配置的意思是:如果请求的body大小超过8k,就会启用磁盘缓存。

考虑到机器的内存比较大,而且需要的qps比较高,部分接口的request输入相对都比较大,可能存在几M的输入,所以所以需要增大这个配置。

kong如何更新nginx相关的配置

问题来了,对于nginx,配置比较容易改,kong还没试过改动配置,admin api也没有相关的信息。

在github仓库 https://github.com/Kong/kubernetes-ingress-controller 的issues搜索了一下,没有直接的指引,所以去kong的官网查了一下

https://docs.konghq.com/1.2.x/configuration/#client_body_buffer_size

基本的配置指引里面还包括一个这样一段话

Environment variables
When loading properties out of a configuration file, Kong will also look for environment variables of the same name. This allows you to fully configure Kong via environment variables, which is very convenient for container-based infrastructures, for example.

To override a setting using an environment variable, declare an environment variable with the name of the setting, prefixed with KONG_ and capitalized.

For example:

log_level = debug # in kong.conf
can be overridden with:

$ export KONG_LOG_LEVEL=error
PermalinkInjecting Nginx directives
Tweaking the Nginx configuration of your Kong instances allows you to optimize its performance for your infrastructure.

When Kong starts, it builds an Nginx configuration file. You can inject custom Nginx directives to this file directly via your Kong configuration.

PermalinkInjecting individual Nginx directives
Any entry added to your kong.conf file that is prefixed by nginx_http_, nginx_proxy_ or nginx_admin_ will be converted into an equivalent Nginx directive by removing the prefix and added to the appropriate section of the Nginx configuration:

Entries prefixed with nginx_http_ will be injected to the overall http block directive.

Entries prefixed with nginx_proxy_ will be injected to the server block directive handling Kong’s proxy ports.

Entries prefixed with nginx_admin_ will be injected to the server block directive handling Kong’s Admin API ports.

For example, if you add the following line to your kong.conf file:

nginx_proxy_large_client_header_buffers=16 128k
it will add the following directive to the proxy server block of Kong’s Nginx configuration:

    large_client_header_buffers 16 128k;
Like any other entry in kong.conf, these directives can also be specified using environment variables as shown above. For example, if you declare an environment variable like this:

$ export KONG_NGINX_HTTP_OUTPUT_BUFFERS="4 64k"
This will result in the following Nginx directive being added to the http block:

    output_buffers 4 64k;

也就是说,nginx的配置,其实可以通过环境变量来注入

kong的helm chart配置更新

kong的安装采用的是helm chart安装的方式
里面涉及到kong的环境变量有两个地方
https://github.com/Kong/charts/blob/master/charts/kong/values.yaml#20

https://github.com/Kong/charts/tree/master/charts/kong#the-env-section

根据文档提示,只要set了values.yaml的env,就可以透传到kong的容器

触发命令

helm upgrade your-release-name --set env.client_body_buffer_size=4096k kong-chart-path

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐