现象
k8s集群中,上传图片时,大于1M就会报错 413 Request Entity Too Large
Nginx Ingress Controller 的版本是 0.29.0
解决方案
1. 修改configmap
kubectl edit configmap nginx-configuration -n ingress-nginx
在 ConfigMap 的 data 字段中设置参数:
data:proxy-body-size: "30m"
示例:
apiVersion: v1
kind: ConfigMap
metadata:name: nginx-configurationnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx
data:proxy-body-size: "30m"
2. 手动重新载入 Nginx
kubectl delete pod -n ingress-nginx [nginx-ingress-controller-pod-name]
3. 验证
查看nginx配置中client_max_body_size的值
kubectl exec -n ingress-nginx [nginx-ingress-controller-pod-name] -- cat /etc/nginx/nginx.conf