<p>I’m deploying 2 services to kubernetes pods which simply echo a version number; echo-v1 &amp; echo-v2</p>
<p>Where echo-v2 is considered the canary deployment, I can demonstrate sticky sessions as canary weight is reconfigured from 0 to 100 using canary &amp; canary-weight annotations.</p>
<p>2 ingresses are used:
The first routes to echo-v1 with a session cookie annotation.
The second routes to echo-v2 with canary true,canary weight and session cookie annotations.</p>
<p>The second ingress I can apply without impacting those sessions started on the first ingress and new sessions follow the canary weighting as expected.</p>
<p>However I’ve since learned that those annotations are for nginx community and won’t work with nginx plus.</p>
<p>How can I achieve the same using ingress(es) with nginx plus?</p>

Ant
<p>This is the ingress configuration that works for me using Nginx community vs Nginx plus.</p>
<p><strong>Nginx community:</strong></p>
<p>(coffee-v1 service)</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/affinity: &quot;cookie&quot;
  name: ingress-coffee
spec:
  rules:
    - http:
        paths:
          - path: /coffee
            pathType: Exact
            backend:
              service:
                name: coffee-v1
                port:
                  number: 80
</code></pre>
<p>(coffee-v2 'canary' service)</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/affinity: &quot;cookie&quot;
    nginx.ingress.kubernetes.io/canary: &quot;true&quot;
    nginx.ingress.kubernetes.io/canary-weight: &quot;100&quot;
  name: ingress-coffee-canary
spec:
  rules:
    - http:
        paths:
          - path: /coffee
            pathType: Exact
            backend:
              service:
                name: coffee-v2
                port:
                  number: 80
</code></pre>
<p><strong>Nginx plus:</strong></p>
<p>(coffee-v1 &amp; coffee-v2 as type 'virtualserver' not 'ingress')</p>
<pre><code>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
</code></pre>
