Situation  地理位置

The rke2-ingress-nginx-controller pods are continuously emitting warning logs indicating that the client request body is being buffered to a temporary file.
rke2-ingress-nginx-controller pod 持续发出警告日志,表明客户端请求体正在缓冲到临时文件。
An example of the logged warning is:
记录警告的一个例子是:
[warn]: *16039 a client request body is buffered to a temporary file /tmp/nginx/client-body/0000019201, client: 10.x.x.x
[警告]: *16039 客户端请求体缓冲到临时文件 /tmp/nginx/client-body/0000019201,客户端:10.x.x.x
This warning persists even when the maximum client body size (client_max_body_size), configured via proxy-body-size, has been set to a large value (e.g., 1024m).
即使通过代理体大小配置的最大客户端体型(client_max_body_size)设置为较大值(例如 1024m)时,该警告仍然存在。

Resolution  结局

To resolve this issue, you must increase the maximum size of the in-memory buffer using the client-body-buffer-size configuration key, which is defined in the NGINX configuration map and managed in RKE2 via a HelmChartConfig resource.
要解决这个问题,你必须使用客户端-主体缓冲区大小配置键来增加内存缓冲区的最大容量,该键在 NGINX 配置映射中定义,并在 RKE2 中通过 HelmChartConfig 资源管理。


Configure Client Body Buffer Size via HelmChartConfig (RKE2)
通过 HelmChartConfig(RKE2)配置客户端体缓冲区大小

To configure NGINX parameters for the bundled rke2-ingress-nginx controller, you create or modify a HelmChartConfig resource in the kube-system namespace. These configurations are passed through the controller.config map.
要配置捆绑的 rke2-ingress-nginx 控制器的 NGINX 参数,你需要在 kube 系统命名空间中创建或修改一个 HelmChartConfig 资源。这些配置会通过 controller.config 映射传递。

In the example below, both the maximum allowed size (proxy-body-size) and the in-memory buffer size (client-body-buffer-size) are configured to a large value (e.g., 5MB, but adjust based on your workload needs):
在下面的示例中,最大允许大小(代理体大小)和内存缓冲区大小(客户端体缓冲区大小)都被配置为较大值(例如 5MB,但可根据你的工作负载需求进行调整):
1. Create or modify the HelmChartConfig resource for rke2-ingress-nginx:
1. 创建或修改 rke2-ingress-nginx 的 HelmChartConfig 资源:
2. Applying the Configuration:
2. 应用配置:
   ◦ Standalone RKE2 cluster: Save this manifest (e.g., /var/lib/rancher/rke2/server/manifests/rke2-ingress-nginx-config.yaml) and restart the rke2-server service.
   ◦ 独立 RKE2 cluster:保存此清单(例如,/var/lib/rancher/rke2/server/manifests/rke2-ingress-nginx-config.yaml),并重启 rke2-server 服务。
   ◦ Rancher-provisioned RKE2 cluster: Apply this YAML in the Additional Manifests section when editing the cluster configuration.
   ◦ Rancher 配置 RKE2 集群 :编辑集群配置时,在附加清单部分应用该 YAML 代码。

apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
 name: rke2-ingress-nginx
 namespace: kube-system
spec:
 valuesContent: |-
   controller:
     config:
       # Configures client_max_body_size (e.g., to prevent 413 errors)
       proxy-body-size: "5m" 
       # Configures client_body_buffer_size (e.g., to prevent disk buffering warnings)
       client-body-buffer-size: "5m" 

   
If the warning persists, ensure the new configurations have been correctly applied and loaded by the NGINX process.
如果警告持续,请确保 NGINX 进程正确应用并加载了新配置。
Confirm that the NGINX configuration has been reloaded, sometimes requiring a manual restart of the rke2-ingress-nginx-controller DaemonSet.
确认 NGINX 配置已重新加载,有时需要手动重启 rke2-ingress-nginx-controller DaemonSet。

Cause  病因

The warning a client request body is buffered to a temporary file occurs because the incoming request body size exceeds the allocated in-memory buffer (client_body_buffer_size), forcing NGINX to write the excess data to a temporary file on disk.
客户端请求主体被缓冲到临时文件的警告是因为输入请求主体大小超过分配的内存缓冲区(client_body_buffer_size),迫使 NGINX 将多余数据写入磁盘上的临时文件。

The distinction is critical:
区别至关重要:
1. client_max_body_size (set via proxy-body-size) limits the total request size (preventing 413 errors).
1. client_max_body_size(通过代理体大小设置)限制总请求大小(防止 413 个错误)。
2. client_body_buffer_size (set via client-body-buffer-size) limits the amount NGINX holds in memory for the request body before writing to disk.
2. client_body_buffer_size(通过客户端-身体-缓冲区大小设置)限制 NGINX 在写入磁盘前为请求体存储的内存容量。
If the warning persists despite a large proxy-body-size, the client-body-buffer-size needs to be increased to prevent disk I/O and performance overhead 
如果警告在代理体大小较大的情况下依然存在,则需要增加客户端体缓冲区大小,以防止磁盘 I/O 和性能开销

Additional Information  附加信息
Environment  环境

An RKE2 cluster using the bundled rke2-ingress-nginx controller.
一个使用捆绑 RKE2-ingress-nginx 控制器的 RKE2 集群。

 访问Rancher-K8S解决方案博主,企业合作伙伴 :
https://blog.csdn.net/lidw2009

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐