Setting up your CI/CD for Kubernetes is complex. Post setup, managing your CI/CD can become quite challenging when your team and infrastructure grow 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 applications teams ship features fast while ensuring best practices for the code base.

In this micro-blog, we will show you how you can create and manage your 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 you validate and test the changes pushed by developers. It is where you run all your test cases(unit and integration tests. After you have validated and tested your codebase, you can build the software artifacts in this step e.g., you can build a container image, or it can be a binary executable.

CD stands for “Continuous delivery”, which is when you push your software artifacts to the production/staging environment in an automated process. In this context, after building a container image and pushing it to the container registry, we will deploy the same image in the Kubernetes cluster with the help of Devtron.

What is Kubernetes Native CI/CD?

The Kubernetes native CI/CD leverages the software delivery workflows 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 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, 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 for our applications.

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 demo application provided by Devtron. You can create a fork for your own here.

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, 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 GitOps configs.

Devtron GitOps

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`.

Devtron create application

Step 3: Adding Github Repository and Build Configuration

The next step is to add the Git Repo 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.

Devtron git repository configuration

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.

Devtron build stage

If you want to build a platform specific image then you can configure that in the advanced settings on the same page.  

Devtron multi-platform Images

Step 4: Configuring Base Deployment Template

Here’s how the base deployment template looks.

Devtron basic deployment template

On this page, you can configure your 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.

Devtron Deployment Template

You can configure your HPA, ingress, security context, keda autoscaling, and many more things just with a few tweaks in the predefined template. With Devtron’s deployment template, you don’t have to write a single YAML file for your Kubernetes configurations.

Step 5: Creating & Triggering a CI-CD Pipelinee

Once you have configured the deployment template, you are ready to build your CI/CD Workflow. Let us go ahead with configuring continuous integration. To know more about other ways of creating pipelines, feel free to read workflow editor documentation.

Devtron CI

Here’s how you will create a build pipeline.

Devtron Build Configurations

Now after the build pipeline is created let’s create the deployment pipeline. Use the `+` icon on the same page to add your deployment pipeline.

Devtron Build Pipeline

The above is a deployment pipeline with a rolling deployment strategy. Here we can also choose the deployment strategy we want to implement for the release. Four deployment strategies are supported by Devtron as of today.

  1. Rolling
  2. Blue Green
  3. Canary
  4. Recreate
Deployment strategy


For now, we will proceed with rolling deployment. Even in the Rolling deployment, we can change the percentages according to our convenience and use cases. The same configuration can be applied to other strategies as well.

Devtron rolling deployment strategy

After setting up the CI/CD pipeline, here’s what the entire pipeline will look like.

Devtron Workflows

To trigger our pipelines we have to go to the `Build & Deploy` section.

For triggering our CI, commit and click on `Start Build`.

Devtron CI logs

Once you have started the build, you can check the logs of the build process and when the build is successful then you can verify the image, built in the artifacts section.

Devtron Build

The `Build & Deploy` section should show you that the build pipeline is successful.

Let’s trigger the deployment pipeline. After the build pipeline is successful, there will be an option to `select image`. Select the image and then click on Deploy.

Devtron deployment

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 for your workloads can also be viewed here.

Here Devtron allows you to have a complete picture of status, deployments, processes, and much more.

devtron-app-details

In case something is breaking you can debug those issues right from your dashboard by checking logs, events, and manifests. Grep the logs right from your browser and if you need more information you can also spin up a shell in the pod to debug the issues further as you can see here in the image below.

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 process by automating your build and continuously testing the codebase. 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.