Use k8s to achieve grayscale release, canary, blue-green release

Introduction #

Ingress-Nginx is a K8S ingress tool that supports the configuration of Ingress Annotations to achieve grayscale publishing and testing in different scenarios. Nginx Annotations supports the following four Canary rules:

  • nginx.ingress.kubernetes.io/canary-by-header: Traffic segmentation based on Request Header, suitable for canary publishing and A/B testing. When the Request Header is set to always, the request will always be sent to the Canary version; when the Request Header is set to never, the request will not be sent to the Canary entry; for any other Header value, the Header will be ignored, and the priority will be The request is prioritized against other canary rules.

  • nginx.ingress.kubernetes.io/canary-by-header-value: The value of the Request Header to be matched, used to inform the Ingress to route the request to the service specified in the Canary Ingress. When the Request Header is set to this value, it will be routed to the Canary entry. This rule allows users to customize the value of Request Header, which must be used together with the previous annotation (ie: canary-by-header).

  • nginx.ingress.kubernetes.io/canary-weight: Traffic segmentation based on service weight, suitable for blue-green deployment, weight range 0 - 100 Routing requests to services specified in Canary Ingress by percentage. A weight of 0 means that the canary rule will not send any requests to the service of the canary entry. A weight of 100 means that all requests will be sent to the Canary entry.

  • nginx.ingress.kubernetes.io/canary-by-cookie: Cookie-based traffic segmentation, suitable for canary publishing and A/B testing. A cookie used to inform the Ingress to route requests to the service specified in the Canary Ingress. When the cookie value is set to always, it will be routed to the Canary portal; when the cookie value is set to never, the request will not be sent to the Canary portal; for any other value, the cookie will be ignored and the request will be compared with other canary rules Compare priorities.

Note: Canary rules are ordered by priority as follows:

canary-by-header - > canary-by-cookie - > canary-weight

We can generally divide the above four annotation rules into the following two categories:

  • Weight-Based Canary Rules

  • Canary rules based on user requests

Note: Ingress-Nginx actually introduces the Canary function in version 0.21.0, so make sure the ingress version is OK

Test, create 2 ingres services

The second service adds ingres annotation

nginx.ingress.kubernetes.io/canary=true
nginx.ingress.kubernetes.io/canary-by-header=canary
nginx.ingress.kubernetes.io/canary-by-header-value=true

test

[root@k8s-node01 ~]# curl -H "canary: true" http://k8s-node02/
4
[root@k8s-node01 ~]# curl http://k8s-node02/
3

金丝雀发布配置

nginx.ingress.kubernetes.io/canary=true
nginx.ingress.kubernetes.io/canary-weight=10

实现蓝绿发布,更简单了,只需要创建对应的pod服务即可。

Guess you like

Origin blog.csdn.net/robinhunan/article/details/128718855