This topic describes the annotation used when you implement a gray release by using the Ingress function provided by Alibaba Cloud Container Service for Kubernetes.

To support a gray release, the Ingress function of Alibaba Cloud Container Service for Kubernetes provides the following annotation: routing rules set by using nginx.ingress.kubernetes.io/service-match and service weight set by using nginx.ingress.kubernetes.io/service-weight.
Note

If you set routing rules by using nginx.ingress.kubernetes.io/service-match and service weight by using nginx.ingress.kubernetes.io/service-weight, the system first determines whether the routing rules set by using nginx.ingress.kubernetes.io/service-match are matched when receiving a request :

  • If no routing rules are matched, the system forwards the request to the application of the earlier version.
  • If the routing rules are matched, the system forwards the request according to the service weight that you set by using nginx.ingress.kubernetes.io/service-weight.

Routing rules set by using nginx.ingress.kubernetes.io/service-match

This annotation is used to set the routing rules for the service of the latest version. The annotation format is as follows:

nginx.ingress.kubernetes.io/service-match: | 
    <service-name>: <match-rule>

Parameter description

service-name: service name. The requests that meet the requirements of the route matching rules are routed to this service.

match-rule: matching rules of routes.
  • Matching types:
    • header: based on the request header. This matching type supports regular expression matches and full expression matches.
    • cookie: based on the cookie. This matching type supports regular expression matches and full matches.
    • query: based on the queried parameter. This matching type supports regular expression matches and full matches.
  • Matching methods:
    • The format of a regular expression match is /{Regular Expression }/.
    • The format of a full match is "{exact expression}"

Configuration examples

# If the request header of a request meets the requirements of the regular expression of foo and ^bar$, the request is forwarded to the new-nginx service.
new-nginx: header("foo", /^bar$/)

# In the request header of a request, if foo fully matches bar, the request will be forwarded to the new-nginx service.
new-nginx: header("foo", "bar")

# In the cookie of a request, if foo matches the regular expression ^sticky-.+$, the request will be forwarded to the new-nginx service.
new-nginx: cookie("foo", /^sticky-.+$/)

# In the query param of a request, if foo fully matches bar, the request will be forwarded to the new-nginx service.
new-nginx: query("foo", "bar")

Service weight set by using nginx.ingress.kubernetes.io/service-weight

This annotation is used to set the traffic weights for the service of the latest version and the service of the earlier version. The annotation format is as follows:
nginx.ingress.kubernetes.io/service-weight: | 
    <new-svc-name>:<new-svc-weight>, <old-svc-name>:<old-svc-weight>

Parameter description

new-svc-name: name of the service of the latest version.

new-svc-weight: weight of the service of the latest version.

old-svc-name: name of the service of the earlier version.

old-svc-weight: weight of the service of the earlier version.

Configuration examples

nginx.ingress.kubernetes.io/service-weight: | 
    new-nginx: 20, old-nginx: 60
Note
  • Service weights are calculated by using relative values. In the preceding example, the service of the latest version is set to 20 weight and the service of the earlier version is set to 60 weight. Therefore, the weight percentage of the latest version service is 25% and the weight percentage of the earlier version service is 75%.
  • In a service group that is composed of services that have the same host and path in an Ingress YAML, the default service weight is 100.