Containerization and OS-level virtualization has enabled unprecedented efficiencies in deploying applications faster and predictably while optimizing hardware resource utilization on the aws management console. With the old ways of deploying applications on the host, immutable VM images were heavy, less portable and provided little flexibility that’s demanded by DevOps-driven continuous delivery process requirements.
A new container-centric infrastructure approach toward application deployment is required to isolate filesystems, processes and resources from each other as well as the host. Kubernetes, the open-source platform automates containerized deployment of application builds, decoupled from the underlying infrastructure. The result is a streamlined approach toward continuous delivery with a portable, extensible and self-healing deployment process.
However, not every build is deployed successfully, and failed deployments can bottleneck or even halt the continuous delivery process.While Jenkins allows manual rollback for failed deployments, DevOps teams moving fast and failing often pursue automated solutions to replace mundane manual rollback processes. So we wrote a script for Kubernetes deployment using Jenkins that will enable you to automatically rollback to a previous known working state in case of failed deployment. Here is the gist link for the sript
Here’s the walk through:
1. Create a Jenkins a job and add Git configuration:
2. Use the example below to check for the template deploy.tml.yaml
in the micro-service:
Template :deploy.tmp.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: __NAME__ spec: replicas: __REPLICA__ template: metadata: labels: app: nginx spec: containers: - name: nginx image: __IMAGE__ ports: - containerPort: 80
3. Set up variables that will be used by the continuous integration Jenkins server. The required piece of information includes the names of the server, container and Docker image. Also specify the number of application versions or parts – known as PODS – on which the Kubernetes platform will run automated deployment operations.
NAME
PODS_COUNT
CONTAINER_NAME
DOCKER_IMAGE
4. Add execute shell as build script and paste the script from this link.
5. Update the Jenkins variables using the existing template deploy.tmpl.yaml.Enter
the location path of the file to start runningcommands against Kubernetes clusters from the appropriate location.
TEMPLATE=$(cat deploy.tmpl.yaml) kubectl=/usr/local/bin/kubectl kubectl="/usr/local/bin/kubectl --server=https://172.31.37.103:8080 --namespace=firefly-sidekiq"
Script automatically rollback in event of unsuccessful deployment. The appropriate function is called to perform this operation for each build deployment. Yaml template has the variables. Utilize different flow patterns for existing and new deployments. Check for existing deployments, perform an update if available and notify the user accordingly. Poll for deployment status again to confirm the updated build has been deployed.
If the existing deployment has not been updated, mark the poll status function as not OK and initiate deployment rollback automatically. Notify the user accordingly. Furthermore, create a deployment first and recheck the poll status to confirm the deployment has indeed been created this time, and notify the user accordingly.
Need help? Contact nCloud if you’re facing issues using Kubernetes for automated deployment and rollback of your application builds within your DevOps environment.