Spinnaker blue/green deployment for Kubernetes
Spinnaker introduced traffic management in Kubernetes deployments in version 1.14. In this blog, we discuss the 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 the 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 a new server group and keep the current server group running without traffic the new deployment must support new server group deployment in parallel to an 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 a pipeline with single Deploy (Manifest) stage to deploy our replicaSet manifest
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 the 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 the first deployment:
Rerun the deployment with version: v2 of replicaset and after Deployment (old version still available for fast rollback):
So in this article, we have shown you how to make deployments in Kubernetes clusters using blue/green deployment strategy using Spinnaker. If you wish to streamline your Continuous Delivery, please read the following articles:
- Spinnaker Pipeline – Blue/Green strategy with external versioning and Kubernetes Deployment object
- Kubernetes Red/Black (Blue/Green) deployments with Spinnaker
If you want to know more about the Spinnaker or request a demonstration, please book a meeting with us.
OpsMx is a leading provider of Continuous Delivery solutions that help enterprises safely deliver software at scale and without any human intervention. We help engineering teams take the risk and manual effort out of releasing innovations at the speed of modern business. For additional information, contact us