In today's fast-paced digital landscape, ensuring the uptime and availability of your applications and services is paramount. Downtime can lead to significant losses and damage. To address these concerns, you need a robust monitoring solution, and Uptime-Kuma, an open-source monitoring tool, fits the bill perfectly. Uptime-Kuma allows you to monitor the uptime and performance of your websites, APIs, and services. In this tutorial, we will delve into the intricacies of deploying Uptime-Kuma on a Civo Kubernetes cluster using Terraform and the Civo command-line tool. This process leverages infrastructure as code and ensures that your monitoring solution is not just dependable but also scalable.
Uptime-Kuma and its Significance
Uptime-Kuma is an open-source, self-hosted status monitoring solution that excels in tracking the availability and response times of your services and websites. It empowers you to take proactive steps by offering insights into your application's performance, customizable alerts, and an intuitive web interface for visualizing historical data. By deploying Uptime-Kuma, you can identify and rectify issues before they adversely affect your users, ensuring an exceptional user experience.
Prerequsites
Before we dive into the tutorial, it's crucial to mention that this guide assumes a basic familiarity with Kubernetes. To effectively follow the steps outlined, you should have the following tools installed:
Additionally, it is essential to ensure that your Civo CLI is ready for use. To do this, you need to log in to your Civo account and generate an API token. This API token is crucial in authenticating Civo CLI and Terraform with your Civo account. Download Civo CLI and set up your Civo account by adding the API token as apikey
.
Installing Uptime-Kuma
To install Uptime-Kuma on the Civo Kubernetes cluster, there are two ways:
- Install from the Civo Marketplace
- Writing complete Terraform script to create a deployment and other required resources.
In this section, we will delve into the process of installing the application from the Civo Marketplace. Civo Marketplace offers a wide range of pre-configured Kubernetes applications, which are specifically designed for seamless integration into Civo Kubernetes clusters.
Moreover, it is important to highlight that these applications can be installed in three distinct ways, providing users with flexibility and choice when it comes to their preferred installation methods, which are:
- While creating and after the creation of cluster via CLI
- While creating a cluster via Terraform
- From the Marketplace tab of web UI once the cluster is created
Installing Uptime-Kuma via the CLI
Now, let's explore how to create a cluster and install an application using the CLI.
Once you have completed the mentioned setup of the CLI, you can create a Civo Kubernetes Cluster using the Civo CLI with just the following command:
civo kubernetes create
This will create a Kubernetes cluster with a random name and default configurations set by Civo.
Moreover, if you want to add an application from the Civo Kubernetes marketplace to the existing cluster, wait till the cluster is created; use the following command:
civo kubernetes application add -c cluster-name uptime-kuma:1GB
However, if you want to add an application while creating a cluster, you can run:
civo kubernetes create cluster-name --applications=uptime-kuma:1GB
Verifying the Application is Installed
First, set the kubectl context to the cluster by executing:
civo kubernetes config cluster-name --save --switch
This will save your cluster config in your local main kubeconfig file and switch the context to your cluster.
When this application is installed, it creates:
- A namespace called kuma
- A persistent volume
- A stateful set
- A service to expose the application
- A traefik ingress for public access to the application
To verify the above resources in your cluster, use:
kubectl get all -n kuma
It should give results like this:
>>> kubectl get all -n kuma
NAME READY STATUS RESTARTS AGE
pod/uptime-kuma-0 1/1 Running 0 6d21h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/uptime-kuma-service ClusterIP 10.43.215.186 <none> 3001/TCP 6d21h
NAME READY AGE
statefulset.apps/uptime-kuma 1/1 6d21h
>>> kubectl get ingress -n kuma
NAME CLASS HOSTS ADDRESS PORTS AGE
uptime-kuma <none> uk.68c4ba6a-80a9-4db1-9397-22acd@26bb35.k8s.civo.com 80 6d22h
kubectl get ingress -n kuma
will show you the host where you can access the application.
In this case, the host is configured as: uk.YOURCLUSTERDNS_NAME
You can find the value of your cluster’s DNS name from the Kubernetes Dashboard. Now, if you hit that particular URL, you will get to see something like this 👇
Create an admin account and set up the monitoring alerts according to your needs, For more information on this, check out their official GitHub.
Installing Uptime-Kuma via Terraform
Let’s move forward to doing the above process via Terraform. To begin, set up the environment by installing and configuring the necessary tools.
Next, we will create the Terraform configuration file that defines the infrastructure resources required for deploying Uptime-Kuma.
First, we need to add a provider in Terraform, and for that, create a provider.tf
file in your local system as below:
# Configure the Civo Provider
terraform {
required_providers {
civo = {
source = "civo/civo"
}
}
}
provider "civo" {
token = "YOUR_CIVO_API_KEY"
}
The token is the API token of the Civo account, you can pass it directly like above or create a variable for it and then pass via a variable, whatever you are comfortable with; check out variables in Terraform here.
Next is to create a main.tf
file, which will consist of code to create the cluster:
resource "civo_firewall" "my-firewall" {
name = "my-firewall"
}
data "civo_size" "small" {
filter {
key = "type"
values = ["kubernetes"]
}
}
resource "civo_kubernetes_cluster" "cluster" {
name = "test1-cluster"
cluster_type = "k3s" # Your choice of cluster type, can be k3s or talos
applications = "Uptime-kuma:1GB"
region = "NYC1" # Your choice of Civo region
firewall_id = civo_firewall.my-firewall.id
pools{
node_count = 1
size = element(data.civo_size.small.sizes, 0).name
}
}
This code, upon applying, will create a firewall and a kubernetes cluster with a small size node and other default configurations.
Once these files are ready, we have to perform terraform commands to create these resources on Civo.
We start with terraform init
to initialize the Terraform and provider plugins.
Then we check what Terraform is planning by doing terraform plan
The plan should be something like this:
>>> terraform plan
Terraform will perform the following actions:
# civo_firewall.my-firewall will be created
+ resource "civo_firewall" “my-firewall" {
+ create_default_rules = true
+ id = (known after apply)
+ name = “my-firewall"
+ network_id = (known after apply)
+ region = (known after apply)
}
# civo_kubernetes_cluster.cluster will be created
+ resource “civo_kubernetes_cluster" "cluster" {
+ api_endpoint = (known after apply)
+ applications = “Uptime-kuma:1GB"
+ cluster_type = “k3s"
+ cni = (known after apply)
+ created_at = (known after apply)
+ dns_entry = (known after apply)
+ firewall_id = (known after apply)
+ id = (known after apply)
+ installed_applications = (known after apply)
+ kubeconfig = (sensitive value)
+ kubernetes_version = (known after apply)
+ master_ip = (known after apply)
+ name = “test1-cluster"
+ network_id = (known after apply)
+ num_target_nodes = (known after apply)
+ ready = (known after apply)
+ region = “NYC1"
+ status = (known after apply)
+ target_nodes_size = (known after apply)
+ pools {
+ instance_names = (known after apply)
+ label = (known after apply)
+ node_count = 1
+ public_ip_node_pool = (known after apply)
+ size = “g4s.kube.xsmall"
}
}
Plan: 2 to add, 0 to change, 0 to destroy.
As I said earlier, it is planning to create a firewall and a kubernetes cluster.
If you are fine with the plan, perform terraform apply
:
>>> terraform apply
civo_kubernetes_cluster.cluster: Creation complete after 1m54s [id=13bd04be-1ca3-4e02-ad1f-d5bc28d9b57b]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
We can verify this from the Kubernetes Dashboard as well 👇
Once the deployment is completed, you can verify that Uptime-Kuma is up and running correctly. The verification and access to the application are the same way as I have mentioned above for CLI. The public access URL will be: uk.YOURCLUSTERDNS_NAME
You can set up the Uptime-Kuma dashboard and perform some basic checks to ensure everything is functioning as expected. On the other hand, it is also easy to destroy the resources created via Terraform, just use terraform destroy
command:
>>> terraform destroy
Plan: 0 to add, 0 to change, 2 to destroy.
civo_kubernetes_cluster.cluster: Destroying... [id=13bd04be-1ca3-4e02-ad1f-d5bc28d9b57b]
civo_kubernetes_cluster.cluster: Destruction complete after 1s
civo_firewall.my-firewall: Destroying... [id=a3e019cf-57a1-4195-a3d8-dbdc1737df28]
civo_firewall.my-firewall: Destruction complete after 4s
Destroy complete! Resources: 2 destroyed.
The resources created will get deleted permanently.
From the Marketplace tab of web UI once the cluster is created
This is the easiest of all methods when the cluster is ready, as it enables us to install an application from the marketplace on our cluster in only a few clicks. Once the cluster is ready, click on the cluster name from the dashboard, and the cluster information tab will be opened. Go to the Marketplace tab and then to the Monitoring tab 👇
Now, scroll down and look for the Uptime-kuma application. Choose the suitable plan 👇
Now, the application will be selected to be installed, scroll down and click on Install Apps.
After a few seconds, you can see the application as installed under the Installed Applications tab 👇
You can access the application in the same way: uk.YOURCLUSTERDNS_NAME
Enjoy exploring Uptime-Kuma!
Summary
In conclusion, we have learned how to successfully deploy Uptime-Kuma, a powerful monitoring tool, with the help of Terraform and Civo CLI on a Civo Kubernetes cluster. By following these step-by-step instructions, you can quickly and effortlessly set up a robust and efficient monitoring solution for your applications and services. With Uptime-Kuma, you will gain valuable insights and real-time data on the uptime and performance of your resources, allowing you to make informed decisions and take proactive measures to ensure a seamless user experience.Further Resources
If you want to keep learning about this topic, check out some of these additional resources:
Happy monitoring and happy DevOps!