In case you're stuck with a file upload problem in one of your app deployed in Kubernetes, this blog may help you.

Just a brief background:

  • We have an app built in Phoenix (Elixir) and is deployed in Kubernetes
  • We used nginx as the ingress controller
  • We have a backend nginx-service that connects to our pods

Like most apps, there will always be some instance that you need to provide a file upload feature to upload pics, files, etc. Nginx and Kubernetes have default limits in the file upload which you will encounter.

413 Request Entity Too Large

In order to fix this, you need to do the following:

  • Set the client-max-body-size to your desired limit in your nginx .conf files.


server {
  listen 80;
  client_max_body_size 50M;

  • Set the client-max-body-size in your ingress config
apiVersion: extensions/v1beta1
kind: Ingress
  name: app-ingress
  annotations: "true" "nginx" "50m" "30s" "20s" "50m"
  • If you want to apply this config all over your nginx-ingress controller, you can set it up in the configmap.yml
apiVersion: v1
  proxy-connect-timeout: "15"
  proxy-read-timeout: "600"
  proxy-send-timeout: "600"
  hsts-include-subdomains: "false"
  body-size: "64m"
  server-name-hash-bucket-size: "256"
  client-max-body-size: "50m"
kind: ConfigMap
  namespace: nginx-ingress
  name: nginx

502 Bad Gateway

This is a wildcard issue. In our experience, our pods gets terminated when we increased the file upload limit. We look on all sides of our app to investigate this. In the end, we found that the resource limits of our containers is the cause of this issue.

         - name: app
               memory: "64Mi"
               cpu: "250m"
               memory: "128Mi"
               cpu: "500m"

By increasing the limits, we were able to solve the problem.