2

I would need to configure client_max_body_size for a specific location in my Ingress configuration file then is the default value. How it is possible to do it? I was looking into the doc but have not found anything. Not don't want do do it globally.

Also if I would use an annotation it would be used for all paths, I just want it for a specific one.

  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "4m"
location /upload-path {
  client_max_body_size 6M;
}
Peter Jurkovič
  • 145
  • 1
  • 8

1 Answers1

3

As per Nginx docs, you can set client_max_body_size in 3 sections:

  • http,
  • server,
  • location

Do set this value, you must change it in nginx ingress controller pod, exactly in /etc/nginx/nginx.conf.

Below example:

$ kubectl exec -ti <ingres-controller-pod> /bin/bash

$ kubectl exec -ti nginx-ingress-controller-6b85b64f49-rwxlf /bin/bash

Edit nginx.conf file.

$ vi /etc/nginx/nginx.conf

In my example hostname from ingress is my.pod.svc.

Now you need to find proper server part of file. You can search it, as it will be commented like below.

## start server <your host name from ingress>

Like below:

 ## start server my.pod.svc                    
        server {                                                   
                server_name my.pod.svc ;   
...

Now you must find proper location. In this example case it will be /pod.

 location ~* "^/pod" {                                                                                                          

                        set $namespace      "default"; 

Here you must specify this value.

As default it is 2M. During change, don't forget about ;.

There is similar thread on Stackoverflow. In that thread you can also find link with another example here.

After this change you will need to reload nginx.

EDIT:

Another option (which was used by OP in this situation) is to use annotation.

client_body_max_size

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

This way it would apply whole cluster.

another annotation that can be use is configuration_snippet annotation. For this example, set size only to /upload-path, it would looks like:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
   name: nginx-snippet
   annotations:
      nginx.ingress.kubernetes.io/configuration-snippet: |

      location /upload-path {

           client_max_body_size 8M;  
      }
PjoterS
  • 615
  • 3
  • 11
  • Hey, thanks. I've decided to do in on an ingress rule level - on in the controller. – Peter Jurkovič Apr 03 '20 at 09:47
  • So have you used annotation `nginx.ingress.kubernetes.io/proxy-body-size` or `configuration-snippet` like here: https://stackoverflow.com/a/59212766/11148139 ? – PjoterS Apr 03 '20 at 10:37
  • I have used the annotation and created a new ingress rule specifically for the path needed. – Peter Jurkovič Apr 03 '20 at 10:38
  • @PjoterS the solution with the configuration-snippet yielded a 503 for the configured location for me. Do you know why that might be? – tschale Jun 29 '22 at 09:22