17

on my Cluster, I'm trying to upload a big file but when I try, I get the 413 Error

error parsing HTTP 413 response body: invalid character '<' looking for beginning of value: "<html>\r\n<head><title>413 Request Entity Too Large</title></head>\r\n<body>\r\n<center><h1>413 Request Entity Too Large</h1></center>\r\n<hr><center>nginx/1.19.3</center>\r\n</body>\r\n</html>\r\n"

I know that this is caused by a default parameter of nginx and I need to override it. On the documentation I've found that this can be done using two ways:

  1. using annotation on ingress config
  2. using a configMap

I have tried both ways with no result.

Here are my yaml: ingress.yml

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "700m"
  name: nginx-ingress
spec:
  rules:
    - host: example.com
      http:
        paths:
          - backend:
              serviceName: nginx-service
              servicePort: 80
            path: /              

and configmap.yml:

apiVersion: v1
data:
  proxy-body-size: "800m"
kind: ConfigMap
metadata:
  name: ingress-nginx-controller
  labels:
    app.kubernetes.io/name: nginx-ingress
    app.kubernetes.io/part-of: nginx-ingress
Jonas
  • 121,568
  • 97
  • 310
  • 388
v2to
  • 409
  • 1
  • 5
  • 11

8 Answers8

18

For future searchs, It works for me:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
  name: docker-registry
  namespace: docker-registry
spec:
rafaelnaskar
  • 619
  • 6
  • 11
  • it works for me, k8s version: v1.26.0,ingress-nginx.controller:v1.4.0 – AlexYu Jan 13 '23 at 04:00
  • 2
    "Setting size to 0 disables checking of client request body size." - See documentation: https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size – ShadowGames Feb 13 '23 at 17:24
9

For NGINX, an 413 error will be returned to the client when the size in a request exceeds the maximum allowed size of the client request body. This size can be configured by the parameter

To configure this setting globally for all Ingress rules, the proxy-body-size value may be set in the NGINX ConfigMap. To use custom values in an Ingress rule define these annotation:

nginx.ingress.kubernetes.io/proxy-body-size: 8m

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#custom-max-body-size

for node.js you might set

app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb' }));
Rafiq
  • 8,987
  • 4
  • 35
  • 35
4

I was with the same problem using Nginx Ingress on GKE.

These are the annotations that worked for me:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.org/client-max-body-size: "0"
    nginx.org/proxy-connect-timeout: 600s
    nginx.org/proxy-read-timeout: 600s

Don't forget to put the correct values for you.

For more details you can see these docs:

  1. Using Annotations
  2. Client Max Body Size

PS I've installed my "Nginx Ingress Controller" following this tutorial.

Thiago G. Alves
  • 1,202
  • 1
  • 14
  • 24
4

There are some good answers here already to avoid that 413.

As for example editing the Ingress (better redeploying) with the following annotations:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"

Furthermore, for NGINX an 413 error will be returned to the client when the size in a request exceeds the maximum allowed size of the client request body. This size can be configured by the parameter client_max_body_size reference.

Toni
  • 1,054
  • 7
  • 12
3

Below configurations worked out for me:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: cs-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/proxy-body-size: 16m

reference: https://github.com/kubernetes/ingress-nginx/issues/4825

Utkarsh Sharma
  • 323
  • 4
  • 14
1

There are few things to have in mind while setting this up:

  1. It is better to recreate the Ingress object rather than edit it to make sure that the configuration will be loaded correctly. Delete the Ingress and recreate it again with the proper annotations.

  2. If that's still not working you can try to use the ConfigMap approach, for example:


apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx
  namespace: ingress-nginx
  labels:
    app: ingress-nginx
data:
  proxy-body-size: "8m"
  1. Notice that setting size to 0 disables checking of client request body size.

  2. Remember to set the value greater than the size of data that you are trying to push.

  3. Use the proper apiVersion based on your Kubernetes version. Notice that:

The extensions/v1beta1 and networking.k8s.io/v1beta1 API versions of Ingress will no longer be served in v1.22.

  • Migrate manifests and API clients to use the networking.k8s.io/v1 API version, available since v1.19.

  • All existing persisted objects are accessible via the new API

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
0

Maybe my experience will help somebody. All my settings were Ok in nginx, but nginx stood behind CloudFlare in Proxy mode. So try to set it to "DNS only" in order to make sure there is nothing between you and nginx.

enter image description here

Michael A.
  • 1,071
  • 12
  • 21
0
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
    nginx.org/proxy_read_timeout: "720s"
    nginx.ingress.kubernetes.io/proxy-body-size: "0"

Above settings work for me on AKS nginx. Zero means no limit and if user want to apply upload limit, just replace 0 with desired limit like 150m.