簡體   English   中英

Kubernetes 和 Nginx 入口 controller 出現 413 錯誤

[英]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”

https://docs.nginx.com/nginx-ingress-controller/configuration/global-configuration/configmap-resource/

我已經在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM