Deploying Devtron in a Local K8s Kind Cluster using Terraform

Short Hands-On guide on how to deploy Devtron in a local Kubernetes cluster created with kind and Terraform

Itchimonji
CP Massive Programming
8 min readJul 19, 2022

--

Photo by Devtron on Github

GitOps, Kubernetes, and Infrastructure as code (IaC) are hot topics at the moment. They bring many advantages making it fairly easy to implement DevOps principles and represent an added value for every team and company.

This article explains how to create a local Kubernetes cluster based on Docker and how to deploy Devtron in it for managing your delivery workflow.

What is GitOps?

GitOps uses Git repositories as a single source of truth to deliver infrastructure as code. Submitted code checks the CI process, while the CD process checks and applies requirements for things like security, infrastructure as code, or any other boundaries set for the application framework. All changes to code are tracked, making updates easy while also providing version control should a rollback be needed. [RedHat]

What is kind and what is it useful for?

Shortly explained, kind is a very powerful tool for deploying local Kubernetes clusters dynamically. You can use different configuration files to create predefined clusters for different use cases. In combination with Terraform you can raise a cluster very quickly and expand it with various configurations. Then you can do your stuff like running tests or CI builds, and after that you can destroy it again — very lightweight, efficient, and it has a single responsibility approach.

Personally, I use kind for local tests, evaluations, trainings, and education.

Creating a kind cluster

To install kind on your machine you can follow the official docs:

It is very simple to create a local cluster using kind. You only need to enter the following command in your terminal:

Often it is advantageous to specify a YAML configuration file for different use cases regarding your cluster: test or production environments, supplier environments, and so on. This way you can manage different IaC projects.

With this configuration file you can create your cluster with a control-plane and two additional nodes that map HTTP and HTTPS protocols.

K9s Tool

To delete the cluster and release the resources, kind gives you the following command:

And to check if all clusters are destroyed you can run the command below which lists all running local clusters:

A simple demo can be found on Github.

Creating a kind cluster with Terraform

Now it is getting even more exciting, as you are creating the same cluster with the configuration file in Terraform.

You can find the original code of this example here. I have changed it a little for this use case.

First of all, you need Terraform files for versions and variables of the resources and providers. In versions you need to define providers for kind and Kubernetes:

In variables you need to define cluster name and the path for the k8s config:

With this you can implement the main file where the kind cluster is defined like the YAML mentioned above.

To start the cluster you need to init and apply Terraform:

K9s Tool

To destroy the cluster you need to run terraform destroy:

A simple demo can be found on Github.

What is Devtron?

Devtron is a tool for rapid, reliable, and repeatable deployments.

Devtron helps you deploy, observe, manage & debug existing Helm apps in all your clusters.

Devtron groups your Kubernetes objects deployed via Helm charts and display them in a slick UI for easier monitoring or debugging. Access pod logs and resource manifests right from the Devtron UI and even edit them!

Control and give customizable view-only, edit access to users on Project, Environment and Application levels

Deploy and manage Helm charts, applications across multiple Kubernetes clusters (hosted on multiple clouds/on-prem) right from a single Devtron setup

[Devtron Github]

Creating a kind cluster with Nginx and Devtron using Terraform

It is very convenient to create a fully configured cluster via Infrastructure as Code. This way you do not have to constantly adjust your code afterwards and everything is automated. This is very easy to handle using kind and Terraform.

The base cluster from the previous step will now be expanded with Nginx and Devtron via Helm Charts. For this, you need to expand the Terraform variables with defined versions and namespaces:

After this, you need to expand the providers, because the Helm and null provider is required:

In addition, the Helm provider must be linked to the path of the Kubernetes cluster configuration:

Devtron configuration

For Devtron you only need a Terraform Helm Release configuration and its values file. This is a very basic configuration. You need to define the name, repository source, and the Chart. Then, you link the YAML file containing the values and create a dependency with depends_on to connect the created cluster.

The values YAML is very simple — at this point of Devtron it only needs the cicd module:

You could also install the cicd module later via the dashboard and skip this step:

Devtron Stack Manager

Nginx configuration

You can find the original Nginx configuration for this setup here.

For Nginx you need a similar configuration as for Devtron. You extend this configuration with the null resource from Terraform to wait for the controller’s availability:

And same as with Devtron, you need the values YAML file for the Nginx configuration:

With this the Nginx configuration is completed.

Bash file and Devtron ingress

The steps above helped you create a basic kind K8s cluster setup with 3 nodes, an Nginx controller, and a Devtron release. To access the Devtron dashboard you need to define an ingress YAML file which depends on the Devtron service. This is a default Kubernets ingress configuration you can find everywhere:

To mix the Terraform code with the base ingress configuration for Devtron you can create a bash file to call the commands in a chain:

Now you only need to run the following command:

After a while (generally within 20 minutes) the whole cluster is created and you can reach the Devtron dashboard via http://localhost:

K9s Tool
Devtron Login Page

Devtron Access

To access Devtron you need to get the base64 decoded password from the secret file. For this you need to run the command below. The default username is admin.

After entering username and password you reach the dashboard where you can see the deployed Helm Charts from the steps before:

Devtron Application Overview

A simple demo can be found at Github.

Important: Installation status

The above install commands for CI/CD integration starts Devtron-operator, which takes about 20 minutes to spin up all of the Devtron microservices one by one. You can check the status of the installation with the following command. Alternatively, you can check the Terraform terminal whether the installation has already been completed.

The command executes with one of the following output messages, indicating the status of the installation:

  • Downloaded: The installer has downloaded all the manifests, and installation is in progress.
  • Applied: The installer has successfully applied all the manifests, and the installation is complete.

Regardless, you can call the dashboard endpoint after about 2 minutes. However, not all features will be visible in the sidebar at this moment.

Devtron Setup Status

Conclusion

From my point of view, Devtron has great potential to become one of the best GitOps tools on the market even though it currently still takes long to create. It contains all of the important tools to manage a whole infrastructure from release to deployment to operation through to monitoring.

Photo by Devtron on Devtron Docs

In this article I showed how to deploy a Devtron environment with Terraform in a local kind K8s cluster. In the next articles I will introduce Devtron in more detail and what is possible with this tool.

Follow me on Medium, or Twitter, or subscribe here on Medium to read more about DevOps, Agile & Development Principles, Angular, and other useful stuff. Happy Coding! :)

--

--

Itchimonji
CP Massive Programming

Freelancer | Site Reliability Engineer (DevOps) / Kubernetes (CKAD) | Full Stack Software Engineer | https://patrick-eichler.com/links