Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes nginx ingress: set client_max_body_size for one subdomain only

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.

like image 730
Eric Guan Avatar asked Oct 16 '25 14:10

Eric Guan


2 Answers

In more recent versions of ingress-nginx, there is a dedicated annotation for the ingress resource called nginx.ingress.kubernetes.io/proxy-body-size:

metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 5tb

If you use the configuration-snippet from this answer, it would currently result in an error like:

[emerg] 551#551: "client_max_body_size" directive is duplicate in /tmp/nginx/nginx-cfg123:321
nginx: [emerg] "client_max_body_size" directive is duplicate in /tmp/nginx/nginx-cfg123:321
nginx: configuration file /tmp/nginx/nginx-cfg123 test failed
like image 180
wvengen Avatar answered Oct 18 '25 18:10

wvengen


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.

like image 23
mdaniel Avatar answered Oct 18 '25 17:10

mdaniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!