Ben T
Ben T

Reputation: 83

Apply nginx-ingress annotations at path level

We are migrating from a traditional nginx deployment to a kubernetes nginx-ingress controller. I'm trying to apply settings at a location level, but can't see how to do so with annotations.

For example, we had:

server {
  listen 80;
  server_name example.com;

  location /allow-big-uploads {
    client_max_body_size 100M;
    ...
  }
}

And we translate to something like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: web-ingress
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 100m <-- this now applies globally
spec:
  rules:
    - host: example.com
      http:
        paths:
          - path: /allow-big-uploads
            backend:
              serviceName: example-svc
              servicePort: 5009

Adding that annotation under the path section doesn't seem to work. Am I missing something?

Upvotes: 8

Views: 5059

Answers (2)

iliefa
iliefa

Reputation: 794

If you have 2 locations on the same host and you want to apply a setting on just one location , you can create 2 ingresses with the same hosts , and apply on the ingress you are interested the configuration snippet annotation:

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#configuration-snippet

nginx.ingress.kubernetes.io/configuration-snippet: |

  more_set_headers "Request-Id: $req_id";

i have tried for this example and it works.

However, when i try to change the client_max_body_size via the configuration snippet , i get the error :

"client_max_body_size" directive is duplicate

Upvotes: 3

Matt
Matt

Reputation: 74791

Annotations can only be set on the whole kubernetes resource, as they are part of the resource metadata. The ingress spec doesn't include that functionality at a lower level.

If you are looking for more complex setups, traefik have built a custom resource definition for their ingress controller that allows more configuration per service. The downside is the definition is not compatible with other ingress controllers.

Upvotes: 5

Related Questions