[英]413 error with Kubernetes and Nginx ingress controller
我正在尝试更改client_max_body_size
值,因此我的 nginx 入口不会返回 413 错误。
我测试了几个解决方案。
这是我的测试配置 map:
kind: ConfigMap
apiVersion: v1
data:
proxy-connect-timeout: "15"
proxy-read-timeout: "600"
proxy-send-timeout: "600"
proxy-body-size: "8m"
hsts-include-subdomains: "false"
body-size: "64m"
server-name-hash-bucket-size: "256"
client-max-body-size: "50m"
metadata:
name: nginx-configuration
namespace: ingress-nginx
labels:
app: ingress-nginx
These changes has no effect at all, after loading it, in the nginx controller log I can see the information about reloading config map, but the values in nginx.conf are the same:
root@nginx-ingress-controller-95db685f5-b5s6s:/# cat /etc/nginx/nginx.conf | grep client_max
client_max_body_size "8m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
我的 nginx-controller 配置使用这个图像:quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.13.0
如何强制 nginx 更改值? 对于我所有的入口,我需要在全球范围内更改它。
您可以使用注释nginx.ingress.kubernetes.io/proxy-body-size
在您的 Ingress 对象中设置 max-body-size 选项,而不是更改基本 ConfigMap。
以下是使用示例:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-app
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
...
要全局设置它,这个configmap.md文档可能会有所帮助。 原来要设置的变量是proxy-body-size
,而不是client-max-body-size
。
部署 helm chart 时,可以设置--set-string controller.config.proxy-body-size="4m"
。
更新:
我遇到了同样的问题,但没有任何解决方案有效。 在阅读了无数具有相同建议解决方案的博客和文档后,我发现它们已经改变了命名约定。
它不再用“proxy-body-size”表示,或者这对我来说永远不起作用。
下面的链接显示要使用的正确 configmap 变量是“client-max-body-size”
我已经在 configmap 上尝试了 proxy-body-size 和 client-max-body-size 并滚动重启了 nginx 控制器 pod,当我 grep pod 中的 nginx.conf 文件时,它返回默认的 1m。 我正在尝试在 Azure Kubernetes 服务 (AKS) 中执行此操作。 我正在与他们支持的人一起工作。 他们说它不在他们身上,因为它似乎是 nginx 配置问题。
奇怪的是,我们在 Azure 中有其他集群,这不是问题,直到我们在一些较新的部署中发现了这一点。 他们提出的最初修复是这个线程中的内容,但它只是拒绝更改。
下面是我的配置图:
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
client-max-body-size: 0m
proxy-connect-timeout: 10s
proxy-read-timeout: 10s
kind: ConfigMap
metadata:
annotations:
control-plane.alpha.kubernetes.io/leader: '{"holderIdentity":"nginx-nginx-ingress-controller-7b9bff87b8-vxv8q","leaseDurationSeconds":30,"acquireTime":"2020-03-10T20:52:06Z","renewTime":"2020-03-10T20:53:21Z","leaderTransitions":1}'
creationTimestamp: "2020-03-10T18:34:01Z"
name: ingress-controller-leader-nginx
namespace: ingress-nginx
resourceVersion: "23928"
selfLink: /api/v1/namespaces/ingress-nginx/configmaps/ingress-controller-leader-nginx
uid: b68a2143-62fd-11ea-ab45-d67902848a80
发出滚动重启后:kubectl rollout restart deployment/nginx-nginx-ingress-controller -n ingress-nginx
Grepping nginx 入口控制器 pod 以查询值现在显示:
kubectl exec -n ingress-nginx nginx-nginx-ingress-controller-7b9bff87b8-p4ppw cat nginx.conf | grep client_max_body_size
client_max_body_size 1m;
client_max_body_size 1m;
client_max_body_size 1m;
client_max_body_size 1m;
client_max_body_size 21m;
我在哪里尝试改变它并不重要。 在全局或 Ingress 路由的 configmap 上.......上面的这个值永远不会改变。
我可以通过在修改 configmap 后重新部署 nginx-ingress 控制器来修复它。
kubectl patch deployment your_deployment -p "{\"spec\": {\"template\": {\"metadata\": { \"labels\": { \"redeploy\": \"$(date +%s)\"}}}}}"
您始终可以进行全局更改并完全禁用它
kubectl -n ingress-nginx patch configmap \
nginx-configuration -p '{"data": {"proxy-body-size": "0"}}'
或设置为 5tb
kubectl -n ingress-nginx patch configmap \
nginx-configuration -p '{"data": {"proxy-body-size": "5tb"}}'
也许最近有些人卡在这里了。 我们刚刚发现nginx.ingress.kubernetes.io/proxy-body-size
不再被应用,正确的注释是:
annotations:
nginx.org/client-max-body-size: "999m"
希望这对其他人有帮助。
这里有关于正确注释是nginx.ingress.kubernetes.io/proxy-body-size
还是nginx.org/client-max-body-size
的混淆。 答案是两者都可能!
在所有相关人员的无懈可击的智慧中,世界上有两个不同的“NGINX入口”。 很难判断你在运行哪个,而且谷歌搜索在这里区分是没有用的(但有什么新的)。
如果你使用的是官方的 NGINX Ingress,正确的注释在这里: https://docs.nginx.com/annginx-ingress/advancedsource-configuration/configuration/
If you are using the official Kubernetes Ingress based on NGINX, the correct annotation is this: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#custom-max-body-size
如果您的入口实现的 Docker 映像名称是k8s.gcr.io/ingress-nginx/controller
,那么您使用的是官方 Kubernetes 版本。 通过消除,您可以确定您是否正在使用 NGINX 实现。
我希望为这个令人困惑的 state 做出贡献的每个人都有一个非常糟糕的一天。 你们的 rest...保持愉快!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.