123. 缓解 Ingress-NGINX 警告:RKE2 中客户端请求主体缓冲到临时文件
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.xThis 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)通过 HelmChartConfigRKE2配置客户端体缓冲区大小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: 5mIf 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