Kubernetes nginx ingress: set client_max_body_size for one subdomain only

8/17/2018

How do I set the client_max_body_size parameter for a single subdomain? I have a server that will accept file uploads up to 5TB. All the examples I've looked at show you how to set it globally. I have multiple rules in my ingress.yaml, I don't want every single rule to inherit the client_max_body_size parameter, only the file upload server should.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-nginx
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: homepage
          servicePort: 80
  - host: storage.example.com
    http:
      paths:
      - backend:
          serviceName: storage
          servicePort: 80

In the above ingress.yaml, I want to set client_max_body_size for the storage service only, which is located at the host storage.example.com.

-- Eric Guan
kubernetes
nginx
nginx-ingress

1 Answer

8/18/2018

Because I don't see client-max-body-size on the list of annotations, that leads me to believe you'll have to use the custom-config-snippet to include the client_max_body_size 5tb; for that Ingress:

metadata:
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      client_max_body_size 5tb;

However, given that you said that you only want it for storage.example.com, you'll need to split the Ingress config for storage.example.com out into its own Ingress resource, since (AFAIK) the annotations are applied to every host: record in the Ingress resource.

-- mdaniel
Source: StackOverflow