Spinnaker introduced traffic management in Kubernetes deployments in version 1.14. In this blog we discuss Blue/Green deployment strategy and how to configure in Spinnaker using traffic management.

Red/Black or Blue/Green Strategy :

  • Red/Black is to deploy a new version of your application alongside the existing version(s), send client traffic to the new version, and then disable traffic to existing version in the cluster.
  • With a red/black deployment, you keep the previous version available as a hot standby to enable painless rollbacks.

Configuring Spinnaker using traffic management :

For managing traffic to new server group and keep the current server group running without traffic the new deployment must support new server group deployment in parallel to existing server group. For this strategy, ReplicaSet kind must be used for deployments.

Traffic management strategy works by adding service selector to replicaSet server group deployed. The ReplicaSet label selectors in the manifest must be different from service selectors to allow the service selectors to be cleanly added and removed without affecting the replicaSet deployments.

Step 1: First, let’s assume we have already deployed a Service manifest with arbitrary selector labels from which we would like our workloads to receive traffic:

kind: Service
apiVersion: v1
metadata:
  name: opsmx-kube-deploy
  namespace: default
spec:
  selector:
    app: opsmx-kube-deploy
  type: NodePort
  ports:
    - name: canary
      port: 8080
      protocol: TCP
      targetPort: 8080

Step 2: Create pipeline with single Deploy (Manifest) stage to deploy our ReplicaSet manifest

Select Service to Manage Traffic to Deployment

apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
  name: opsmx-kube-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      version:  'v1' 
  template:
    metadata:
      labels:
        version: 'v1' 
    spec:
      containers:
        - image: 'docker.io/opsmx/restapp:v1'
          imagePullPolicy: Always
          name: restapp
          ports:
            - containerPort: 8080
              name: http
              protocol: TCP
            - containerPort: 9090
              name: prometheus
              protocol: TCP

Step 3 : Run your pipeline, manifest deployed will be modified with insertion of “app: opsmx-kube-deploy” as follows.

apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
  name: opsmx-kube-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      version:  'v1' 
  template:
    metadata:
      labels:
        version: 'v1' 
        app:  opsmx-kube-deploy
    spec:
      containers:
        - image: 'docker.io/opsmx/restapp:v1'
          imagePullPolicy: Always
          name: restapp
          ports:
            - containerPort: 8080
              name: http
              protocol: TCP
            - containerPort: 9090
              name: prometheus
              protocol: TCP

Rerun the deployment. Server Groups after first deployment:

Rerun the deployment with version: v2 of replicaset and after Deployment (old version still available for fast rollback):