Getting started with Devtron

Siddhant KhistySiddhant Khisty
11 min read

A lot of organizations use Kubernetes for deploying, monitoring, and scaling their applications. This does have several benefits as Kubernetes provides a lot of useful features. However, Kubernetes by itself, without any integrations is very plain.

When working with Kubernetes, we generally use a ton of third-party applications such as ArgoCD, Prometheus, Graphana, Terraform, and countless others. All these tools increase the number of things that Kubernetes can do, which in turn benefits the organizations.

However, just because these tools can provide features that make things easier, does not mean that they are easy to install and get started with. Many applications are installed into Kubernetes using Helm. This does have some advantages, but like everything, there are also disadvantages.

The most annoying drawback of using helm is that it uses rollouts instead of deployments. What this means is that if you use kubectl delete resource for some reason, the resource will not automatically recreate. Check out this article to learn more about the challenges with Helm

Devtron

Devtron is an open-source tool that will provide a solution to the challenges with Helm. It uses Helm charts to install tools and automatically replies to any deleted resources and also makes it easier to troubleshoot.

Currently, Devtron has only a CI/CD integration in its stack manager, but you can deploy other helm applications as well. You will get a better understanding of what Devtron can do once you follow the tutorial in this blog and get some hands-on experience.

The whole tutorial is divided into 3 parts:

Installing Devtron

The first thing to do before we can get started with actually installing or using Devtron is getting a Kubernetes Cluster. You can use a local setup with minikube or kubeadm but there seem to be some errors with those, so the installation could be difficult.

For this tutorial, I'm going to set up a cluster on Civo, mainly because it is a lightweight Kubernetes, and we can get the cluster in under 2 minutes. You can use a different cloud provider if you are familiar with it.

Creating a cluster of Civo

After you create a Civo account and enter your card details, you should have 250$ worth of free credits. Head over to the Kubernetes dashboard from the menu on the left, and click on Create new Cluster

Now you need to define your cluster name, firewall, and network settings. You can leave the settings at their default value, or you can create your settings and use them.

Note, the system requirements for Devtron may vary depending on your use case. Refer to the below table to determine how many resources to provision. I used a large cluster, which is overkill for a demo. You can use a medium cluster for your CI/CD activities.

You can select some of the applications from the Civo Marketplace, but you may get duplicates if you install the same ones using Devtron. By default, the metrics server, and nodeport will be selected. You can leave them as is, or deselect them. After that, we wait. It should take roughly 2 minutes to create the cluster

Once your cluster has been created, download the Kubeconfig file. We will be using this to interact with our cluster using kubectl commands.

After you have downloaded the Kubeconfig file, locate the .kube folder in your local system and move the Civo config file to this folder. For Linux, it should be a hidden file in the home directory. For Windows, it might be your user folder. In any case, it will be a hidden file, so make sure you can see hidden files.

By default, the Civo Kubeconfig will be named something like civo-cluster-name-Kubeconfig. kubectl will not know that it has to interact with this file, so rename the file to config.

Now just to make sure that you are connected to your Civo cluster, open the terminal and run kubectl get nodes. If you get a similar result as below, with your cluster name, then we can proceed to the next step. If not, you may have not installed kubectl properly.

Installing Devtron

Now that we have installed provisioned our cluster and connected to it, we can proceed to install Devtron. Make sure you have Helm installed before proceeding further.

To install Devtron you need only 2 commands and a bit of patience. We will be installing Devtron using helm. You can copy the below command as is and paste it into your terminal. The first one adds Devtron's helm repository, and the second one installs the Devtron operator.

helm repo add devtron https://helm.devtron.ai

helm install devtron devtron/devtron-operator --create-namespace --namespace devtroncd

Now before entering the suggested commands, you should run kubectl get pods -n devtroncd -w. This will let you see the pods created by the Devtron chart. Before executing the above commands, you should wait for all the pods to start running to avoid any errors.

Once all the statuses of the pods in the devtroncd namespace say either Completed or Running, you can enter the following command to get a link to the Devtron dashboard.

kubectl get svc -n devtroncd devtron-service -o jsonpath='{.status.loadBalancer.ingress}'

The value after hostname is what you want to copy and paste into the browser. You should get a neat dashboard like this one.

To get the password for your dashboard, simply type in the below command, paste the result into the password section, and log in.

kubectl -n devtroncd get secret devtron-secret \
-o jsonpath='{.data.ACD_PASSWORD}' | base64 -d

Installing the CI/CD functionalities

If you followed the above steps correctly, you should be greeted by a similar-looking window such as this one. If you look on the left, there are only a few options. Click on the last option called Devtron Stack Manager.

From here, click on the Devtron Stack Manager, then click on the Build and Deploy (CI/CD) button. From there you can install the CI/CD functionalities. This will take a while, so you can go and brew a cup of coffee in the meantime or explore the dashboard.

Note, once the CI/CD integration is successfully installed, you should get a popup saying that the Devtron UI needs to be updated. Click on the pop-up and update the UI, and you will get the updated dashboard.

Potential Problems

  • If you have kubectl installed, but don't see a .kube directory in Home, then you can create it manually. It should work.

  • After installing Devtron, and entering the command for getting the dashboard link, you may get an empty result. This just means that the service is still being created. You need to wait a while then try again.

  • After pasting the load-balancer link in your browser, you may get a cannot connect to server error. Several things can cause this, the most common reason can be because the Devtron pod is not running. In this case, you only need to wait a while. Other reasons can be because of faulty DNS settings. Every cloud provider has some documentation on setting up a proper DNS so you can refer to that.

  • While trying to install the CI/CD integration, you may get an error such as timeout or serviceAccount not found. For the first one, just click the retry button, as for the second one, you will need to wait a while. The serviceAccount not found means that a Devtron pod is still being created.

Deploying Applications with CI/CD

Before you, we deploy an application to run a pipeline with, head over to the Global Configurations, go to Container Registries, and add a registry. I have added a Docker registry here. You will have to enter your registry credentials so keep them in mind.

You will also want to add a Git Account so we can provide the link to a repository to build and deploy.

Creating a Nodejs Application

Once you've set up your container registry, you should see a screen like this. What we will be doing now, is deploying a simple Nodejs application using Devtron, and adding a CI/CD pipeline to it. So go ahead and click on Create Custom App.

In the pop-up that appears, enter the name of your application, and select a project. You can find the project list in the Global Configurations. The default project will be the same as your cluster name.

We want to create a blank project since we don't have any other applications deploying on Devtron at the moment. After selecting the settings, click on Create App.

Setting up configurations

Now we have created an empty application. All that's left is to configure it. The first thing to do is tell Devtron which application we want to build and deploy. You can select any git repository, such as GitHub, GitLab, etc.

Under the account name, select GitHub public, and add this repo link. This is the application that we will be building and deploying.

Kubernetes uses container images to deploy applications. So we will be building the Node app into a container image. To let Kubernetes know where to pull the image from, we will have to upload it to a container registry.

The next setting will be to define a container repository. This is where the built image will be pushed, and then the image will be pulled while deploying.

Also, if your Dockerfile, which is used to build an image, is not in your root directory, then change the path of the Docker File location.

The next step is to edit the deployment template according to our needs. For this application, we need to change only one field. Use CMD + F inside the YAML editor and search for service. Change the type to LoadBalancer, and click on save.

Next, we want to create a workflow. From the workflow editor, select a Continous Integration pipeline. This will use the deployment template which we defined earlier and use for the CI/CD settings.

After adding the pipeline, you can hover over the Build, and click on the plus to add a Deploy to your workflow. Now your pipeline is ready to test your application.

Watch the magic happen

Head over to the Build & Deploy tab, select build material, and click on start build. The image will be built and pushed to the container repository which you previously defined. You can click on details to see every step that is happening.

After the image has been successfully built and pushed to the container repository, it will automatically head on to deployment. You may have to click on select image and select the correct image, in case there are multiple images.

You can now head over to App Details to see how your application is performing, its health, deployment status, and more.

If you want to see the deployments of your application, head over to the Deployment Metrics tab and select your environment to see how many successful or failed deployments have occurred.

Potential errors

  • Your image build may fail if the container repository you mentioned does not exist. Make sure that the name of the repository is in the correct registry and exists.

  • If your Git repository does not have a Dockerfile, you may not be able to proceed to the build config settings.

Helm Charts

Now that we have deployed our application successfully, it's time to add some custom Prometheus monitoring.

Note, Devtron does not have a monitoring integration yet, so you will have to either visit the Prometheus server or connect your cluster with an editor such as Lens to see the Prometheus stats.

From the menu on the left, head over to the Chart store, and you can see a list of available charts. Note this is not an exhaustive list, and you can add more charts here. These are just a few essential charts that come with Devtron.

On the left, you can see all the helm repositories we are currently using. These are just a few repositories that come with Devtron. You can add more later.

Now to deploy Prometheus, first, we need to find it. Scroll through the chart list, or use the search function to find the kube-prometheus-stack.

Once here, all we need to do is click on Deploy, edit the YAML if needed, and deploy it.

Using custom charts

Let's say you have created a custom chart, or don't see the chart which you want in the Chart store.

For this first, you need to find the chart you want in an artifact repository. I will be adding the Kubecost chart.

Next, head over to the Global Configurations, and Chart repositories, and click on add a new chart. Give a name to your chart repository, add the repo link and click save.

You will now be able to see this chart in the chart store. From there you can edit the YAML and deploy it.

In this way, it is possible to integrate any tool into your cluster easily with the help of Devtron. You can add chart repositories for any artifact store.

Other Features of Devtron

Devtron has a ton of other features such as security to scan and secure your clusters, and a bulk edit feature which lets you update the deployment template, config maps, and secrets for multiple applications in one go without having to do it individually for every app.

To know more about Devtron, check out the documentation and join the Discord Community.

You can also contribute to the project on GitHub.

14
Subscribe to my newsletter

Read articles from Siddhant Khisty directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Siddhant Khisty
Siddhant Khisty