Setup Grafana loki into my EKS cluster

Pavithrasandamini
2 min readMay 23, 2024

--

grafana loki

Hi folks, today I’m going to show you how to set up Grafana Loki into your current EKS cluster for better logging system. This guide will walk you throgh it step by step. Before we dig in we need some pre-requeisits. I will menstion those below. These dependencies should be in your local machine before we start.

  1. AWS CLI: Installed and configured.
  2. kubectl: Installed and configured to work with your EKS cluster.
  3. Helm: Installed for managing Kubernetes applications.

After installing them, you can check the versions and check they properly installed and configured into you aws account.

Then as the fisrt step, we need to set up an EKS cluster. If you don’t have one you need to set up that from scratch. Since this is not about EKS, I will only provide you some commands and guides for that. Here I will create my EKS cluster using eksctl.


eksctl create cluster \
--name my-cluster \
--region us-west-2 \
--nodegroup-name linux-nodes \
--node-type t3.medium \
--nodes 3

So, this will create your cluster. It gives name as my-cluster and created in region us-west-2. You can customize those according to your wish.

In the next step we will work with helm and stuff. As I mentioned before you should install helm on your local machine. Now we will install helm in our ec2 instance, we can do it by executing the following command in EC2 console or local machine terminal that you connected to your EC2 instance. (If you wondering how to connect EC2 using via your local machine click here)

curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

And then add grafana and loki helm repositories with running the following command.

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

SO, now you have successfully added grafana into your instance and updated the helm. Now it’s time to deploy loki and grafana in your EKS cluster. Use the following commands for that,

helm upgrade --install loki grafana/loki-stack \
--namespace loki \
--create-namespace \
--set grafana.enabled=true \
--set prometheus.enabled=true \
--set loki.persistence.enabled=true \
--set loki.persistence.storageClassName=gp2 \
--set loki.persistence.size=10Gi

After that, we need to install promtail as well. Because we need someone for log shipping. To install that use this command below.

helm upgrade --install promtail grafana/promtail \
--namespace loki \
--set config.lokiAddress=http://loki.loki:3100/loki/api/v1/push \
--set config.filepath=/var/log/containers/*.log

Ok folks, now we are almost done. If I explain what I have done, after adding helm into your EC2 instance we install Loki, Grafana, and Promtail, these applications are deployed to your EKS cluster based on the configurations you specify in the Helm commands.

Now we have successfully setup grafana and loki in your EKS cluster.

So, you can test further using checking the pods and accessing your grafana board.

--

--