Simplifying the Kubernetes CI/CD Pipeline

TL;DR: Setting up your CI/CD for Kubernetes is challenging. But Devtron simplifies the whole process to just minutes in a low/ no-code approach by abstracting out all the domain complexities.

a year ago   •   8 min read

By Abhinav Dubey, Anurag,

Table of contents

Setting up CI/CD pipelines for Kubernetes can be complex. Post setup, managing the CI/CD can become quite challenging when your team and infrastructure grows quickly. An efficient and fully automated CI/CD plays an important role in ensuring you ship your features faster.  By leveraging CI/CD, you can guarantee that the application teams ship new features faster while ensuring best practices for the code base.

In this micro-blog, we will see how easily one can create and manage the CI/CD pipelines with Devtron, but before doing that let's do a quick refresher on CI/CD.

What is CI/CD?

CI stands for “Continuous integration”, which is the stage where we build, validate, and test the code changes pushed by developers. It is where you run all your test cases i.e, unit and integration tests. After we have validated and tested the codebase, we can build the software artifacts in this step for e.g, we can build a container image (often a Docker image), or it can be a binary executable.

CD stands for “Continuous delivery” (often also called “continuous deployment), which is when you use automation to push your software artifacts to the production/staging environment. In this context, after building a container image and pushing it to the container registry, we deploy the same image in the Kubernetes cluster with the help of Devtron. Devtron is one of many CD tools (available as open source or paid version) that DevOps professionals deploy to automate the software development and delivery lifecycle.

What is Kubernetes Native CI/CD?

The Kubernetes native CI/CD leverages software deliveryworkflows by being part of the Kubernetes cluster. The benefit of using Kubernetes native CI/CD is that your build step will happen inside a pod, and you don’t need to provision or connect any other compute resources externally for your CI. From a security perspective, this method is recommended as all of our secrets & external credentials are within the cluster. Kubernetes automatically handles the complex container orchestration and deployment process to ensure that your CD process consistently and reliably deploys cloud-native applications (often in the form of microservices).

Kubernetes Native CI/CD with Devtron

When you're managing your pipelines with YAML, you need to write the workflow and update it repeatedly. Understanding YAML, examining the build process, learning different Linux commands, deploying code manually, and learning Kubernetes is hard for a developer. They need something intuitive, simple and doesn’t require domain expertise. Even if you don’t know much about Kubernetes deployments, you should be able to develop, execute & trigger your builds & deployments.

This is what we are trying to solve using Devtron. It gives you an intuitive dashboard to help you quickly set up and manage your CI/CD pipelines on Kubernetes. Let's install Devtron, and set up some CI/CD pipelines to deploy our Kubernetes applications to production environments.

For installing Devtron, refer to the installation documentation. After installing Devtron, we will port-forward the Devtron service to get the dashboard URL since we are installing it on a local machine.

kubectl -n devtroncd port-forward service/devtron-service 8000:80 &

After this, you should be able to access the Devtron dashboard on localhost port 8080.

For demonstrating the CI/CD pipeline, let's use a nodejs demo application provided by Devtron on GitHub repository.

After getting this, you need to set the global configurations for your application. For setting global configuration refer to the documentation.

Step 1: Enabling GitOps

To enable GitOps (provided by Argo CD), go to global configuration and then use any Git provider for authentication. In our case, we have used GitHub. It is recommended to create a new GitHub organization of all your GitOpsconfigs.

GitOps Configs

Step 2: Creating application

Now let’s move ahead and create our first application on Devtron. Provide the App Name i.e demo-application, assign it a project i.e. devtron-demo and then click on Create App.

Create App

Step 3: Adding GitHub Repository and Build Configuration

The next step is to add the Git repository (aka. code repository) URL of your source code from where it is being hosted. If you want to deploy an application which is in a private repo, explore the Git Accounts Docs.

Adding Git Repository

Now once we have set up our repository, we need to set the build configuration. The build configuration is required to pull and push your container images. You can change the registry to use docker, ECR, GCR, etc, which can be configured from container registries under Global Configurations.

We have now integrated Buildpacks with which you can build OCI-compliant container images directly from your code.

Build Configurations

If you want to build a platform specific image then you can configure that in the advanced options in Build Configurations.

Buildx Multi-Platform Builds

Step 4: Configuring Base Deployment Template

Base Deployment Template is where all magic happens. Devtron displays a fined grained configurations, abstracting out all the Kubernetes config complexities and packages the template in a helm chart. The deployment template consists of almost all major configurations that would be required for a production grade micro service and it comes with two display options - Basic (GUI Mode) & Advanced (YAML Configs).

Deployment Template GUI Mode

You can configure ContainerPort, set Requests & Limits for your deployment, provide Environment Variables, etc. There’s also an advanced option from which you can get the detailed YAML configurations that Devtron will use during deployment and overwrite the same. Here’s a glimpse of how the deployment template looks.

Base Deployment Template

You can configure Horizontal Pod Autoscaling, Ingress, Security Context, Keda Autoscaling, Volume Mountsand many more Kubernetes configurations just with a few tweaks in the predefined template. With Devtron’s deployment template, you don’t have to worry about writings tons of YAML file for your Kubernetes configurations.

Step 5: Creating & Triggering a CI/CD Pipeline

Once you have configured the deployment template, you are ready to build your CI/CDWorkflow. Let us go ahead and configure continuous integration. To know more about different ways of creating pipelines, feel free to read workflow editor documentation. In this example, we will build & deploy from Devtron Dashboard.

Workflow Editor - Build & Deploy from Devtron

Now, let's create our CI Build Pipeline and configure the pipeline details. In CI pipeline, you can configure vulnerabilities scanning, pre/ post build stages, give the source type i.e, Branch Fixed, Regex, Pull Request or Tag Creation for building images and lot more.

Build Stage - CI Pipeline

Now after the creating build pipeline, let’s create the Deployment Pipeline. Use the + icon on the same page to add your deployment pipeline. With Devtron, you can create as many pipelines as you want, be it sequential pipelines or deploy to multiple environments from same build.

In Deployment Pipeline you can configure pre/ post deployment stages, out-of-the-box integrations of deployment strategies i.e, Rolling, Recreate, Blue-Green and Canary deployment. It also allows you to choose different deployment strategies for different environments in same application. The default deployment strategy is Rolling as you can see in the below image.

In this blog, we will proceed with Blue-Green deployment strategy (considered a zero-downtime strategy) to deploy our containerized applications. You can checkout the deployment strategy configurations and make changes depending upon your use-case. This configuration change is application for all other deployment strategies.

Blue-Green Deployment Strategy

After configuring the CI & CD pipelines, here’s how the entire pipeline looks like. We can create multiple workflows with different configs for different environments and build type in same application.

Isn't it interesting!!
Build & Deploy Workflow

Now that pipelines are created, we need to trigger our pipelines and for that we have to go to the Build & Deploy section.

For building image, click on Select Material -> Select the Commit for which you want to build -> Click on Start Build.

Start Build

Once the build is initiated, we can check the logs of the build process and when the build is successful then we can verify the image built in the artifacts section. It also allows you to check the previous builds, and all necceary audit info required in the dashboard as you can see in the image below.

Build History for CI Pipeline

Let’s trigger the deployment pipeline. After the build pipeline is successful, there will be an option to select image in Build & Deploy page. Select the image and then click on Deploy. We can also check the commit and security details against which deployment is being initiated. Once deployment is started, Devtron gives you details of all stages along with K8s Configurations against each deployment. In CD pipelines as well, we get all the audit info regarding the deployment as you can see in the image below.

Deployment History for CD Pipeline

Step 6: App Details

Once your application is deployed, you can view detailed information about your application in the App Details. All the health related information of your workloads and application metrics can be easily monitored from App Details tab.

After the application is succesfully deployed, it gives you a 360 degree view of all info regarding the application and allows you perform different pod operations such as view logs, exec into terminal, check manifests, events and also comes with Logs Analyzer that allows grep on multi-container logs. It also shows all the Kubernetes resources associated with particular application in a grouped manner that comes very handy for debugging and observability (Prometheus and Grafana can easily be deployed through Devtron). Using the real-time observability information, a good determination can be made if this has been a successful rollout or if a rollback is needed.

App Details of deployed application

Conclusion

In this blog we have learned about Kubernetes CI/CD and how easily it can be set up using Devtron in just 3 minutes with all the best practices and GitOps. One of the main benefits of a quick Kubernetes CI/CD setup is that it can speed up the whole release methodology by automating your build and continuously testing the codebase. It also makes it really easy to deploy application between the various cloud providers (Amazon AWS, MicrosoftAzure, Google GCP), or even on-premises, abstracting away from proprietary management tools. Developers don’t need to build and test manually. A fast, reliable, and efficient Kubernetes CI/CD will lead to better products and happier customers.

To know more about how easily you can set up Kubernetes CI/CD with Devtron, join our dedicated Discord community and ask your queries about Kubernetes and all things Cloud-Native. Do give us a star ⭐️ on GitHub if you liked Devtron.

Spread the word

Keep reading