Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Uploads larger than 1 MB fail with 413 behind the Kubernetes NGINX Ingress controller

Error413 Request Entity Too Large

Short answer

The ingress-nginx controller limits request bodies to 1m by default and answers 413 above that. Raise the limit with the nginx.ingress.kubernetes.io/proxy-body-size annotation on the Ingress that serves the upload route, or set the proxy-body-size key in the controller ConfigMap to change the default for every Ingress.

  • Applies to ingress-nginx controller 1.x, Kubernetes 1.31
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Send a file just over 1 MB through the Ingress host and read the status line. A 413 from nginx means the body-size limit, not your application.

    head -c 2000000 /dev/zero > big.bin && curl -i -F file=@big.bin https://example.com/upload
  2. 2Match what you see, then jump to its fix

    1. 1413 comes from nginx and the Ingress has no proxy-body-size annotationThe default proxy-body-size of 1m applies to this IngressFix
    2. 2Many services need larger uploads and each Ingress hits 413You want a new default for every Ingress in the clusterFix
    3. 3The annotation exists but 413 continuesThe annotation key is wrong or sits on the wrong objectFix

What does the error look like?

  • 413 Request Entity Too Large
  • Uploads of a few MB fail, small files work

Cause 1 of 3

The default proxy-body-size of 1m applies to this Ingress

1Check

The controller documentation lists a default of 1m for the proxy-body-size setting, and says a 413 is returned when a request exceeds the allowed size.

kubectl get ingress my-ingress -n my-namespace -o yaml

2Fix

Add the annotation to the Ingress that serves the upload path, with a size above your largest file.

kubectl annotate --overwrite ingress my-ingress -n my-namespace \
  nginx.ingress.kubernetes.io/proxy-body-size=50m

3Verify

Repeat the upload; the status is no longer 413.

curl -i -F file=@big.bin https://example.com/upload

Confirmed by kubernetes.github.io

Did this fix it?

Cause 2 of 3

You want a new default for every Ingress in the cluster

1Check

proxy-body-size is also a key of the controller ConfigMap, where the default is 1m. An annotation on one Ingress overrides it for that Ingress only.

kubectl get configmap -n ingress-nginx

2Fix

Set the key in the ConfigMap that your controller reads. Its name depends on how the controller was installed, so find it first.

# controller ConfigMap
data:
  proxy-body-size: "50m"

3Verify

Repeat the upload test against a different Ingress that has no annotation.

curl -i -F file=@big.bin https://example.com/other-upload

Confirmed by kubernetes.github.io

Did this fix it?

Cause 3 of 3

The annotation key is wrong or sits on the wrong object

1Check

The exact key is nginx.ingress.kubernetes.io/proxy-body-size, a string value such as 8m, and it belongs on the Ingress object that routes the failing path, not on the Service or Deployment.

kubectl get ingress -A | grep example.com

2Fix

Set the exact key with kubectl annotate on the right Ingress. kubectl refuses to change an existing annotation unless --overwrite is given.

kubectl annotate --overwrite ingress my-ingress -n my-namespace \
  nginx.ingress.kubernetes.io/proxy-body-size=50m

3Verify

Upload the large file again.

curl -i -F file=@big.bin https://example.com/upload

Confirmed by kubernetes.io

Did this fix it?

How do I stop it coming back?

  • Decide an upload limit per route and set it on that route's Ingress in the manifest, not by hand.
  • Keep the same limit in the application (for example its own body-size setting) so one layer does not reject first.
  • Add a large-file upload to your post-deploy smoke test.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.