fbpx
How to Deploy Grafana on Kubernetes

This article will walk you through the process of deploying Grafana on Kubernetes, specifically using k3s and Helm, and making it accessible via a NodePort on your VPS (Virtual Private Server). We’ll assume you have k3s and Helm already installed. If not, please refer to their respective official documentation to get started.

Grafana stands out as a compelling open-source platform that enables users to visualize, analyze and correlate metrics from various data sources in the vast world of observability and monitoring. On the other hand, Kubernetes is a well-known open-source platform that streamlines the deployment, scaling, and management of containerized applications. By offering a reliable solution for monitoring your Kubernetes clusters, deploying Grafana on Kubernetes can significantly improve your DevOps procedures.

Prerequisites

Before you embark on this journey, ensure that you have the following:

  • A Kubernetes cluster running (in this case, k3s)
  • Helm, the package manager for Kubernetes, installed
  • A VPS with a public IP address
  • Basic understanding of Kubernetes and Helm charts

Step 1: Setting Up Helm Repository

We must first include the repository for the Grafana Helm chart. Charts are the packaging format that Helm uses. A chart is a collection of documents that list related Kubernetes resources.

The Grafana repository can be added to Helm by running the following command:

helm repo add grafana https://grafana.github.io/helm-charts

Next, update the Helm repositories:

helm repo update

Step 2: Deploying Grafana on Kubernetes

Now, we are ready to deploy Grafana. We will use the Helm chart from the repository we added earlier. However, we need Grafana to be accessible from the external IP of our VPS. To achieve this, we need to configure the service type as NodePort in the values file.

Create a file named values.yaml:

service:
  type: NodePort

Then, deploy Grafana with the custom configuration:

helm install -f values.yaml grafana grafana/grafana
How to Deploy Grafana on Kubernetes

This command will deploy Grafana on the Kubernetes cluster with a NodePort service, which will be accessible from the external IP.

Step 3: Accessing Grafana Dashboard

You should go to the Grafana dashboard once it has been deployed. To accomplish this, you must locate the Grafana user’s admin password. Execute the upcoming command:

kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

This command decodes the admin password from base64 after retrieving it from the Kubernetes secret.

Next, retrieve the NodePort assigned to the Grafana service:

kubectl get svc grafana

You should see the NodePort under the “PORT(S)” column.

Now, you should be able to access the Grafana dashboard at http://<EXTERNAL-IP>:<NODEPORT>. Use the username admin and the password you retrieved earlier to log in.

How to Deploy Grafana on Kubernetes

Step 4: Customizing Grafana on Kubernetes

For your particular requirements, Grafana deployed in its default configuration might not be adequate. You might want to alter the default admin password, set the persistence, or enable plugins when configuring the Grafana deployment.

Update your values.yaml file with your custom configuration:

adminPassword: mypassword
persistence:
  enabled: true
  size: 10Gi
plugins:
  - grafana-clock-panel
  - grafana-simple-json-datasource
service:
  type: NodePort

Then, upgrade Grafana with the custom configuration:

helm upgrade -f values.yaml grafana grafana/grafana
Deploy Grafana on Kubernetes

Step 5: Integrating Grafana with Prometheus

Grafana supports many data sources, including Prometheus, a popular open-source monitoring system and time series database. If you have Prometheus running in your Kubernetes cluster, you can integrate it with Grafana.

First, add the Prometheus data source in Grafana. Go to the Grafana dashboard, then “Configuration” > “Data Sources” > “Add data source.” Select “Prometheus” and fill in the URL of your Prometheus server.

Next, you can create a dashboard to visualize the Prometheus metrics. Go to “Create” > “Dashboard” > “Add new panel,” select the Prometheus data source, and start creating your queries.

Grafana on Kubernetes

Final Thoughts

Because Grafana provides Helm charts, deploying Grafana on Kubernetes using Helm is a simple procedure. You can keep an eye on your applications and services from any location by making it reachable via a NodePort.

Remember that this is just a starting point for you. Grafana offers a wide range of plugins and data sources, and it is highly customizable. Learn more about Grafana’s capabilities by perusing the documentation and community.


1 Comment

How To Install And Configure Docker Swarm On Ubuntu 22.04 - Virtono Community · September 27, 2023 at 11:51 AM

[…] Ubuntu cluster to guarantee the functionality and performance of your applications. Prometheus and Grafana are two applications you can use to collect and display metrics. In order to handle increased […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.