Apply nginx-ingress annotations at path level

眉间皱痕 提交于 2021-02-04 08:07:27

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/60749036/apply-nginx-ingress-annotations-at-path-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!