Ingress NGINX annotations
文章目录
今天看到文章说IngressNGINX实现灰度,仔细看原来是通过annotations来实现,于是简单的查了下官网,发现有几个有意思的annotations还是蛮有用的,记录下。
nginx.ingress.kubernetes.io/service-upstream
当设置为true时生效,默认为false。该参数也可以通过全局的configMap属性service-upstream来开启
By default the NGINX ingress controller uses a list of all endpoints (Pod IP/port) in the NGINX upstream configuration.
The
nginx.ingress.kubernetes.io/service-upstreamannotation disables that behavior and instead uses a single upstream in NGINX, the service’s Cluster IP and port.
这个注解的好处是:
This can be desirable for things like zero-downtime deployments
使用后引入的新的问题:
- Sticky Sessions will not work as only round-robin load balancing is supported.
- The
proxy_next_upstreamdirective will not have any effect meaning on error the request will not be dispatched to another upstream
不过以上的问题我认为并不重要,没有几个应用是通过网关做会话保持的了;另一个更不值得一提
nginx.ingress.kubernetes.io/canary
配合以下可以实现灰度:
nginx.ingress.kubernetes.io/canary-by-headernginx.ingress.kubernetes.io/canary-by-header-valuenginx.ingress.kubernetes.io/canary-by-header-patternnginx.ingress.kubernetes.io/canary-by-cookienginx.ingress.kubernetes.io/canary-weightnginx.ingress.kubernetes.io/canary-weight-total
指导步骤:
- 创建两个不同的
Deployment与Service - 创建正常的
ingress,该规则不需要加注解 - 创建灰度的
ingress,该ingress的path与hostname一致,不一致的是service名称,以及增加注解
限速相关
以下当初限速时,默认返回的是503,建议通过修改configMap的limit-req-status-code与limit-conn-status-code将状态码修改成一个自定义的如533,然后返回一个友好提示页面
nginx.ingress.kubernetes.io/limit-rps
限制单个IP的每秒的请求数
nginx.ingress.kubernetes.io/limit-rpm
限制单个IP的每分钟的请求数
nginx.ingress.kubernetes.io/limit-connections
限制单个IP的并发连接数
nginx.ingress.kubernetes.io/configuration-snippet
用以增加额外的NGINX配置,定制化时很有帮助,比如我们针对某个Ingress不记录日志
|
|
文章作者 UnknowName
上次更新 2022-01-19