4

I want to increase size of post body of each request in Ingress. So I add the

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

in yaml file ingress(in view/edit yaml file of rancher) but it doesn’t work. When I get the describe of ingress with kubectl I dont see the added annotation but i see the new added mapping. Hereis the configs:

YAML file:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/configuration-snippet: |-
      set $test_host "testdms.test.com"
      if ($host == $test_host) {
        return 301 $scheme://$test_host/webui/;
      }
    nginx.ingress.kubernetes.io/proxy-body-size: 8m
  creationTimestamp: 2018-09-11T12:19:02Z
  generation: 116
  name: test-dms
  namespace: test-dms
  resourceVersion: "95490045"
  selfLink: /apis/extensions/v1beta1/namespaces/test-dms/ingresses/test-dms
  uid: de7c4c1b-b5bc-11e8-84c0-005056bf6431
spec:
  rules:
  - host: testdms.test.com
    http:
      paths:
      - backend:
          serviceName: ingress-e5a45b0dc688c653b79d4b5942ebbe7c
          servicePort: 80
        path: /test
status:
  loadBalancer:
    ingress:
    - {}
    - ip: 198.100.101.171
    - ip: 198.100.101.172
    - ip: 198.100.101.173
    - ip: 198.100.101.61

describe result:

Annotations:
  configuration-snippet:  set $test_host "testdms.test.com"
if ($host == $test_host) {
  return 301 $scheme://$test_host/webui/;
}
Events:
  Type    Reason  Age                       From                      Message
  ----    ------  ----                      ----                      -------
  Normal  UPDATE  36s (x38 over 2h)         nginx-ingress-controller  Ingress test-dms/test-dms
  Normal  UPDATE  21s (x47 over 23d)        nginx-ingress-controller  Ingress test-dms/test-dms
  Normal  UPDATE  <invalid> (x47 over 23d)  nginx-ingress-controller  Ingress test-dms/test-dms
  Normal  UPDATE  <invalid> (x84 over 64d)  nginx-ingress-controller  Ingress test-dms/test-dms
  Normal  UPDATE  <invalid> (x39 over 12d)  nginx-ingress-controller  Ingress test-dms/test-dms
mohammad_1m2
  • 1,571
  • 5
  • 19
  • 38
  • If for no other reason, [set requires a trailing `;`](https://nginx.org/en/docs/http/ngx_http_rewrite_module.html#set) – mdaniel Mar 26 '19 at 04:30
  • 1
    You could disable the limit all together by using `nginx.ingress.kubernetes.io/proxy-body-size: 0`. Also, can you try deleting and recreating the Ingress? What version of Rancher are you using? Can you give more elaborate steps to reproduce the problem? If possible, can you give simplified yaml code to copy/paste and check? – leodotcloud Apr 12 '19 at 01:49

3 Answers3

5

You need to add quotes (e.g. "8m"), like this:

nginx.ingress.kubernetes.io/proxy-body-size: "8m"
segFault
  • 3,887
  • 1
  • 19
  • 31
benCat
  • 124
  • 3
  • 7
  • 1
    Interestingly, the documentation gets this wrong. https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#custom-max-body-size – alex Jul 10 '21 at 19:22
  • @ChristopherGertz what about "because it's working" ? This is the right answer, what's your trouble ? – benCat May 10 '23 at 07:00
  • Sorry, I meant to leave a comment with my downvote. Must have forgotten. Quoting strings is optional in most cases within yaml. Writing `8m` or `"8m"` means exactly the same. In the cases where it does matter (e.g. `true`) you would get a type error. The documentation is not "wrong" in this sense. I also prefer to have the Quotes but this is not the solution to this problem. If this answer worked for anyone (did not for me), it might be because the file itself changed and reset some cache? Hard to tell. – Christopher Gertz May 11 '23 at 09:29
4

Amendment of the ingress objects in K8s sometimes misbehave, so it's recommended to re-create rather than edit.

If it still didn't work, try to set this value globally for all ingress rules using a configmap

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: nginx
      namespace: ingress-nginx
      labels:
        app: ingress-nginx
    data:
      proxy-body-size: "8m"
A_Suh
  • 3,727
  • 6
  • 22
  • Yes, configmap works fine. I want to config this param only for this ingress. I must be check the re-create. Thanks – mohammad_1m2 Apr 26 '19 at 20:26
0

The annotation

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

being ignored could be the result of using the wrong implementation of nginx-ingress controller. Not sure if this is the case, here. Which implementation did you use?

See this answer by ololoepepe for details.

Christopher Gertz
  • 1,826
  • 1
  • 15
  • 9