kubernetes Canary部署期间粘性会话的Nginx plus入口示例

bvjveswy  于 2022-11-21  发布在  Kubernetes
关注(0)|答案(1)|浏览(125)

我正在向Kubernetes pod部署2个服务,这些服务只是回显一个版本号;回声-v1和回声-v2
在echo-v2被视为canary部署的地方,我可以演示当使用canary和canary-weight注解将canary weight从0重新配置为100时的粘滞会话。
使用2个入口:第一个路由到echo-v1,带有会话cookie注解;第二个路由到echo-v2,带有canary true、canary weight和会话cookie注解。
我可以应用第二个入口,而不会影响在第一个入口开始的那些会话,新会话按照预期遵循金丝雀加权。
然而,我后来了解到,这些注解是为nginx社区提供的,不能在nginx plus中使用。
我如何使用nginx plus的入口(es)实现同样的效果?

jdzmm42g

jdzmm42g1#

这是我使用Nginx社区与Nginx plus的入口配置。

Nginx社区:

(咖啡-v1服务)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/affinity: "cookie"
  name: ingress-coffee
spec:
  rules:
    - http:
        paths:
          - path: /coffee
            pathType: Exact
            backend:
              service:
                name: coffee-v1
                port:
                  number: 80

(coffee-v2“金丝雀”服务)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-weight: "100"
  name: ingress-coffee-canary
spec:
  rules:
    - http:
        paths:
          - path: /coffee
            pathType: Exact
            backend:
              service:
                name: coffee-v2
                port:
                  number: 80

Nginx加:

(coffee-v1和coffee-v2作为类型“虚拟服务器”而不是“ingresss”)

apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
  name: cafe
spec:
  host: cloudbees-training.group.net
  tls:
    secret:  cloudbees-trn.aks.group.net-tls
  upstreams:
    - name: coffee-v1
      service: coffee-v1-svc
      port: 80
      sessionCookie:
        enable: true
        name: srv_id_v1
        path: /coffee
        expires: 2h
    - name: coffee-v2
      service: coffee-v2-svc
      port: 80
      sessionCookie:
        enable: true
        name: srv_id_v2
        path: /coffee
        expires: 2h
  routes:
    - path: /coffee
      matches:
        - conditions:
            - cookie: srv_id_v1
              value: ~*
          action:
            pass: coffee-v1
        - conditions:
            - cookie: srv_id_v2
              value: ~*
          action:
            pass: coffee-v2
# 3 options to handle new session below:
#
# 1) All new sessions to v1:
#      action:
#        pass: coffee-v1
#
# 2) All new sessions to v2:
#      action:
#        pass: coffee-v2
#
# 3) Split new sessions by weight
#    Note: 0,100 / 100,0 weightings causes sessions 
#    to drop for the 0 weighted service:
#      splits:
#        - weight: 50
#          action:
#            pass: coffee-v1
#        - weight: 50
#          action:
#            pass: coffee-v2

相关问题