Gatus is a health dashboard that gives you the ability to monitor your services using HTTP, ICMP, TCP, and even DNS queries as well as evaluate the result of said queries by using a list of conditions on values like the status code, the response time, the certificate expiration, the body and many others. The icing on top is that each of these health checks can be paired with alerting via Slack, PagerDuty, Discord, Twilio and more.
In this guide, we will configure Gatus as a health dashboard tool using Kubernetes.
Checkout How to install and configure Gatus for health check monitoring Using Docker Compose.
Prerequisites:
- You have a cluster running with access to create resources
- You have kubectl installed locally
I assume that you have a kubernetes cluster up and running with kubectl setup on your workstation. If not please checkout these guides:
- How to set up Kubernetes Cluster on Ubuntu 20.04 with kubeadm and CRI-O
- How to set up Kubernetes Cluster on Debian 11 with kubeadm and CRI-O
- How to Setup a Kubernetes Cluster with K3S in Rocky Linux 8
- How to use Terraform to create a vpc network and a GKE in GCP
- How to Set up Prometheus Node exporter in Kubernetes
Latest Gatus is available as a docker image in its official docker hub account. We will use that image for the setup.
Setting up Kubernetes Manifests
Once you have the prerequisites in place, we can create kubernetes resource manifests.
Namespace
In Kubernetes, a namespace provides a mechanism for isolating groups of resources within a single cluster. Names of resources need to be unique within a namespace, but not across namespaces. Namespace-based scoping is applicable only for namespaced objects (e.g. Deployments, Services, etc) and not for cluster-wide objects (e.g. StorageClass, Nodes, PersistentVolumes, etc).
Let us create a namespace for our gatus resources. Save the following in namespace.yaml
:
|
|
Then execute the following command to create a new namespace named gatus.
|
|
Create a Config Map To Externalize Gatus Configurations
All configurations for Gatus are part ofconfig.yaml
file that defines the endpoints to be monitored and the alert channels. This config file will be specified when starting the application.
A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume. We sill specify our configfile map as a configmap and pass to the deployment as a configuration file in volume.
Create a file called config-map.yaml
and add the following file contents:
|
|
In the above defined configurations, we are defining slack webhook for alert notifications when thresholds defined trigger an error. We are also defining two endpoints for app one and app two. Finally we are persisting the data in postgres.
Execute the following command to create the config map in Kubernetes.
|
|
Create a Gatus Deployment
A Deployment provides declarative updates for Pods and ReplicaSets. You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.
In our case, we will use the docker-hub provided image and mounting the predefined configmap as a volume mounted in /config
.
Save the following content to deployment.yaml
.
|
|
Create a deployment on monitoring namespace using the above file.
|
|
You can check the created deployment using the following command.
|
|
Connecting To Gatus Dashboard
You can view the deployed Gatus dashboard in three different ways.
- Using Kubectl port forwarding
- Exposing the Gatus deployment as a service with NodePort or a Load Balancer.
- Adding an Ingress object if you have an Ingress controller deployed.
Using Kubectl port forwarding
Using kubectl port forwarding, you can access a pod from your local workstation using a selected port on your localhost
. This method is primarily used for debugging purposes.
First, get the Gatus pod name.
kubectl get pods --namespace=gatus
The output will look like the following.
|
|
Execute the following command with your pod name to access Gatus from localhost port 8080.
Note: Replace gatus-b8895b7b-bpmfn with your pod name.
|
|
Now, if you access http://localhost:8080
on your browser, you will get the Gatus home page.
Exposing Gatus as a Service [NodePort & LoadBalancer]
To access the Gatus dashboard over a IP
or a DNS
name, you need to expose it as a Kubernetes service.
Create a file namedservice.yaml
and copy the following contents. We will expose Gatus on all kubernetes node IP’s on port 40000
.
Note: If you are on AWS, Azure, or Google Cloud, You can use Loadbalancer type, which will create a load balancer and automatically points it to the Kubernetes service endpoint.
|
|
Create the service using the following command.
|
|
Once created, you can access the Gatus dashboard using any of the Kubernetes nodes IP on port 40000
. If you are on the cloud, make sure you have the right firewall rules to access port 40000
from your workstation.
Exposing Gatus Using Ingress
If you have an existing ingress controller setup, you can create an ingress object to route the Gatus DNS to the Gatus backend service.
Also, you can add SSL for Gatus in the ingress layer. You can refer to the Kubernetes ingress TLS/SSL Certificate guide for more details.
Here is a sample ingress object.
|
|
Using Kustomize
Kustomize introduces a template-free way to customize application configuration that simplifies the use of off-the-shelf applications. Now, built into kubectl
as apply -k
.
In our case, to avoid multiple kubectl apply -f <filename>
we can use kustomize to define all the resources then apply as one. Save the following as kustomization.yaml
.
|
|
Then apply using this command:
|
|
Conclusion
In this article, we learnt how to set up Gatus on Kubernetes.