Simplifying the Kubernetes CI/CD Pipeline
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 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 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 the CI/CD Pipeline?
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 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 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. Also, Kubernetes is not the forte of developers, and should not invest time in learning complex kubectl commands. Instead, an abstraction of the top of Kubernetes would be helpful and improve the developer productivity. 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.
Refer to the installation documentation. for installing Devtron. After installation, port forward the Devtron service to get the dashboard URL if installing it on a local machine. If you are using managed Kubernetes services like EKS, AKS, and GKE, a load balancer will be automatically provisioned if the cluster has relevant access.
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 the 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
With Devtron, you are day-1 GitOps enabled. To enable GitOps (the enterprise management of 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.
Step 2: Creating an 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
.
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 that is in a private repo, explore the Git Accounts Docs.
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. To learn more about cloud-native buildpacks, please refer to this blog.
If you want to build multi-arch container images then you can configure that in the advanced options in Build Configurations
. It just takes a single checkbox to enable multi-arch container images which is compatible with ARM as well as AMD machines.
Step 4: Configuring Base Deployment Template
Base Deployment Template is where all magic happens. Devtron displays a fined-grained configuration, 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 microservice and it comes with two display options - Basic (GUI Mode) & Advanced (YAML Configs).
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.
You can configure Horizontal Pod Autoscaling
, Ingress
, Security Context
, Keda Autoscaling
, Volume Mounts
and 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 writing tons of YAML files for your Kubernetes configurations.
One of the advantages of the deployment template provided by Devtron is that you don't even need to worry about the compatibility of the object with respect to the Kubernetes version. Click here to learn more about how Devtron helps you in Kubernetes cluster upgrades.
Step 5: Creating & Triggering a CI/CD Pipeline
Once you have configured the deployment template, you are ready to build your CI/CD workflow. 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.
Now, let's create our CI Build Pipeline
own and configure the pipeline details. In the 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 a lot more.
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 the 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 the 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 applied to all other deployment strategies.
After configuring the CI & CD pipelines, here’s what the entire pipeline looks like. We can create complex multi-cluster workflows with different configs for different environments and build types for the same application. Unlike tools like Jenkins, you don't need to create multiple applications to be deployed on multiple environments. Devtron streamlines the application management, deployed across multiple clusters and environments.
Isn't it interesting!!
Now that pipelines are created, we need to trigger our pipelines and for that, we have to go to the Build & Deploy
section.
To build an image, click on Select Material
-> Select the Commit
for which you want to build -> Click on 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 necessary audit info required in the dashboard as you can see in the image below.
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.
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 about your workloads and application metrics can be easily monitored from App Details
the tab.
After the application is successfully deployed, it gives you a 360-degree view of all info regarding the application and allows you to 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.
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 easy to deploy applications 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.