在路径级别应用 nginx-ingress 注释 [英] Apply nginx-ingress annotations at path level
问题描述
我们正在从传统的 nginx 部署迁移到 kubernetes nginx-ingress 控制器.我正在尝试在 location
级别应用设置,但看不到如何使用注释进行操作.
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.
例如,我们有:
server {
listen 80;
server_name example.com;
location /allow-big-uploads {
client_max_body_size 100M;
...
}
}
我们翻译成这样:
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
在 path
部分下添加该注释似乎不起作用.我错过了什么吗?
Adding that annotation under the path
section doesn't seem to work. Am I missing something?
推荐答案
注释 只能在整个 kubernetes 资源上设置,因为它们是资源的一部分 元数据.入口规范 不包括较低级别的功能.
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.
如果您正在寻找更复杂的设置,traefik 已经构建了一个 自定义资源定义 用于他们的入口控制器,允许每个 服务.缺点是定义与其他入口控制器不兼容.
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.
这篇关于在路径级别应用 nginx-ingress 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!