You can use this module like below. This shows how to create the resources for spinnaker. This module will create IAM policies and kubernetes cluster.
Run terraform, you can use the --var-file
option for customized paramters when you run the terraform plan/apply command.:
terraform init
terraform plan
terraform apply
After then you will see so many resources like EKS, IAM and others on AWS.
Run terraform:
$ terraform destroy
Blue/Green 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.
Spinnaker pipeline deployment on Kubernetes
In my scenario, I will design a Spinnaker pipelines using the simple web app image. And here I am going to use the Spinnaker expressions feature on Spinnaker, to develop this solution. This solution uses Kubernetes service object as Load Balancer to switch traffic from blue to green or vice versa, based on matching selector labels in service object to that of spec.template.metadata.labels in deployment object.
- To manage versions, use of parameterized deployment manifest such as given below:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
release: '${parameters.release}'
name: 'crpdemo-${parameters.release}'
namespace: default
spec:
minReadySeconds: 5
selector:
matchLabels:
app: crp
replicas: 2
template:
metadata:
labels:
app: crp
release: '${parameters.release}'
spec:
containers:
- name: crpdemo
image: subinmt1991/simpleapp:${parameters.release}
ports:
- containerPort: 80
- Assuming service object pre-exist with “release” as one of the selector labels such as given below, and holding the “release” value same as mentioned in first deployment release:
apiVersion: v1
kind: Service
metadata:
name: crpdemo-svc
namespace: default
labels:
app: crp
spec:
ports:
- port: 80
protocol: TCP
selector:
app: crp
release: '${parameters.release}'
type: LoadBalancer
- The Spinnaker pipeline should consist of all required parameters for release and stage.
- Deploy Stage for Blue Deployment
- In this scenario, the Spinnaker pipeline should consist of 3 stages.
- Patch Stage for service to share traffic between existing blue and upcoming green.
- Deploy Stage for Green deployment.
- Patch Stage for service to switch traffic completely on Green deployment.
app: remove
path: /spec/selector/release
spec:
selector:
release: '${parameters.release}'
- With both approaches, rollout and rollback can be achieved with parameters of the given choice. While going for the second design, we can achieve a blue-green strategy with smooth transitioning of traffic as well as non-live deployment to achieve a quick rollback.
- The above-discussed pipelines can be extended to use Git/Bitbucket-based Kubernetes artifacts instead of text-based. And further can be parameterized to use as a pipeline template for different teams.
- The older deployments can be removed by executing either of the below two options:
- By deleting Deployments from UI (Infrastructure tab > Clusters sub-tab)
- By creating a separate pipeline, which contains delete manifest stage and release parameter.
- This approach also assumes a robust external versioning system for release management.
To ensure users traffic is routed to the correct pod (the one deployed with your latest version of the app), we need to remove the older versions.
Here I am use release version as one of the labels for my pods. In addition, the version label gives us a distinction between old and latest.
- Create a new pipeline for destroy older deployments.
- Then click ‘Add Stage’, select Delete Manifest.
- In the Manifest section
- Provide Account, Namespace,selector, kind and Labels
In the 'Settings' section, check the checkbox labeled ‘Cascading’ to eliminate having orphaned resources.
The deployment strategies play a vital role in achieving faster continuous delivery (CD). The blue-green strategy is one of the prominent production deployment strategies, used by organizations. The above steps help in understanding as well as achieving a blue-green strategy in a containerized production environment using Kubernetes objects and Spinnaker pipelines.