Canary Deployment

Requirements

Make sure you have Nginx Ingress deployed on your cluster:

https://kubernetes.github.io/ingress-nginx/deploy/

Deploy app v1

kubectl create -f - <<EOF

apiVersion: v1
kind: Service
metadata:
  name: my-app-v1
  labels:
    app: my-app
spec:
  ports:
  - name: http
    port: 80
    targetPort: http
  selector:
    app: my-app
    version: v1.0.0
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-v1
  labels:
    app: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
      version: v1.0.0
  template:
    metadata:
      labels:
        app: my-app
        version: v1.0.0
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9101"
    spec:
      containers:
      - name: my-app
        image: containersol/k8s-deployment-strategies
        ports:
        - name: http
          containerPort: 8080
        - name: probe
          containerPort: 8086
        env:
        - name: VERSION
          value: v1.0.0
        livenessProbe:
          httpGet:
            path: /live
            port: probe
          initialDelaySeconds: 5
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /ready
            port: probe
          periodSeconds: 5

EOF

Deploy ingress for app v1

Deploy app v2

Deploy ingress canary for app v2

Note the following annotations:

They ensure only 10% of the traffic will be redirected to this host.

To test run the following command:

Roll out ingress for app v2

First, delete the ingress canary:

Then roll out the change.

References

https://medium.com/google-cloud/kubernetes-canary-deployments-for-mere-mortals-13728ce032fe

Last updated