Monitor your Kubernetes Cluster (EKS) with Prometheus and Grafana

What is Prometheus?

  • Prometheus is an open-source system monitoring and alerting tool.
  • It doesn't use protocols such as SNMP or some sort of agent service. Instead, it pulls/scrapes metrics from a client/target over HTTP and places the data into its local time series database that you can query using its own DSL.
  • It uses exporters that are installed and configured on the clients in order to convert and expose their metrics in a Prometheus Format. And then Prometheus server scrapes the exporter for metrics.
  • You can access the default Prometheus UI via port 9090 on its server.
Prometheus
  • Users also have the ability to build dashboards and integrate their visualization software, such as Grafana.
  • t uses a separate component for alerting called the AlertManager. The AlertManager receives metrics from the Prometheus server and then it is responsible for grouping and making some meaningful information about the metrics and then forwarding an alert to your chosen notification system.
  • You can learn more about Prometheus here.

What is Grafana?

  • Grafana is multi-platform open-source analytics and interactive visualization software.
  • It is a solution for running data analytics, pulling up metrics, and monitoring our apps with the help of d ashboards.
  • It provides charts, graphs, and alerts for the web when connected to supported data sources.
Grafana
  • It provides you with tools to turn your time-series database (TSDB) data into graphs and visualizations.
  • You can learn more about Grafana here.

Why do we need System Monitoring?

  • To detect and prevent failures, it is very convenient to have a good monitoring tool that provides you with a solid monitoring system.
  • Monitoring systems are responsible for controlling the technology used by companies in order to analyze their operation and performance.
  • Understanding the state of your infrastructure and systems is essential for ensuring the reliability and stability of your services.
  • Information about the health and performance of your deployments not only helps your team react to issues but also gives them the security to make changes with confidence.

What is Helm?

  • Helm is a package manager for Kubernetes.
  • By using Helm, you can install the Helm charts.
  • The Helm chart is not a data visualization tool. A Helm chart is a collection of YAML files.
Helm
  • You will put all your YAML files in a package. And this package is pushed to any public or private repositories.
  • You can access the repositories using the helm command.

In simple terms, Helm charts are a bundled collection of custom YAML files.

  • You can learn more about Helm from here.

Prerequisite

  1. An AWS Account
  2. Basic knowledge of Prometheus, Grafana, Helm, and Kubernetes
  3. An EKS Cluster with Helm installed on it

Step 1: Create an EKS Cluster

I've already created my EKS Cluster with helm installed on it. You can follow the below blog to create your own EKS Cluster.

Provision an AWS EKS Cluster using Terraform

I've my 'EKS-Cluster' ready for this tutorial.

EKS Cluster

Here, I've created an EKS cluster with 3 Nodes.

$ kubectl get nodes
NAME                        STATUS   ROLES    AGE    VERSION
ip-10-0-2-85.ec2.internal Ready <none> 114m v1.20.15-eks-ba74326
ip-10-0-2-89.ec2.internal Ready <none> 113m v1.20.15-eks-ba74326
ip-10-0-3-70.ec2.internal Ready <none> 112m v1.20.15-eks-ba74326
EC2 Instances
VPC

Step 2: Create Namespaces for Prometheus & Grafana

Before doing the installation of Prometheus & Grafana in our EKS Cluster, first, we are creating 2 different namespaces each for Prometheus & Grafana. You can create namespaces of Prometheus and Grafana by running the following command:

$ kubectl create ns prome   theus
namespace/prometheus created
$ kubectl create ns grafana
namespace/grafana created

Here, both Prometheus & Grafana namespaces have been created.

Step-3: Install required Helm Repositories

Run the following command to install Prometheus's Helm Repository:

$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

Run the following command to install Grafana's Helm Repository:

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

Now we've successfully added the Prometheus's and Grafana's Helm repositories into our cluster.

Step 4: Install Prometheus

You can run the following command to Install Prometheus:

$ helm install prometheus prometheus-community/prometheus --namespace prometheus --set    alertmanager.persistentVolume.storageClass="gp2" --set server.persistentVolume.storageClass="gp2"

You'll get the following output.

The above command will create different Kubernetes (k8s) resources in the Prometheus namespace. By running the following command you can check all the resources.

$ kubectl get all -n prometheus

Output:

Step-5 Install Grafana

You can run the following command to Install the Grafana:

$ helm install grafana grafana/grafana --namespace grafana --set persistence.storageClassName="gp2" --set persistence.enabled=true --set adminPassword='EKS' --values ./grafana.yaml --set service.type=LoadBalancer

You'll get the fo llowing output.

The above command will create different Kubernetes (k8s) resources in the Grafana namespace. By running the following command you can check all the resources.

$ kubectl get all -n grafana

Output:

Step-6 Access Prometheus UI

Here, we've successfully installed Prometheus and Grafana in our EKS cluster. Now in order to access the UI of Prometheus, we need to use the concept of Port Forwarding.

Run the following command for Port-Forwarding:

$ kubectl port-forward -n prometheus deploy/prometheus-server 8080:9090

You can access Prometheus UI at <http://localhost:8080>

  • Prometheus Dashboard:
  • < /ul>
    UI of Prometheus
    • Targets:
    UI of Prometheus

    Step-7 Access Grafana UI

    We already have deployed the Grafana as a Load Balancer service in our EKS cluster. So in order to access Grafana's UI, you can run the following command:

    $ kubectl get svc -n grafana

    You can access Grafana's UI by DNS of the Load Balancer.

    UI of Grafana

    Step-8 Create Dashboard in Grafana

    In Grafana we can create various kinds of dashboards as per our needs. We also have pre-created dashboards in Grafana and we can import them us ing the Dashboard number. For this tutorial, we will import one of the pre-created dashboards. Click on Import and add 3119 (ID of the dashboard)
    It will import the below dashboard.

    Grafana Dashboard

    You can view different details related to our Kubernetes Cluster like Network I/O, Cluster Memory Usage Cluster CPU usage, etc. We can modify the dashboard as per our needs also.

    Grafana Dashboard
    Grafana Dashboard
    Grafana Dashboa rd
    Grafana Dashboard

    Here, in the Grafana you can make changes as per your requirements. You can explore more about EKS, Prometheus, and Grafana.

    If you find this blog please follow me on LinkedIn and Twitter. I would like to connect with you and have a conversation about DevOps/Cloud topics.

    LinkedIn: https://www.linkedin.com/in/aniket-patel-2a52851a3/

    Twitter: https://mobile.twitter.com/aniii_patel12

    Follow me here for more interesting blogs like this.


    Monitor your Kubernetes Cluster (EKS) with Prometheus and Grafana was originally published in Towards AWS on Medium, where people are continuing the conversation by highlighting and responding to this story.

    Namaste Devops is a one stop solution view, read and learn Devops Articles selected from worlds Top Devops content publishers inclusing AWS, Azure and others. All the credit/appreciations/issues apart from the Clean UI and faster loading time goes to original author.

Comments

Did you find the article or blog useful? Please share this among your dev friends or network.

An android app or website on your mind?

We build blazing fast Rest APIs and web-apps and love to discuss and develop on great product ideas over a Google meet call. Let's connect for a free consultation or project development.

Contact Us

Trending DevOps Articles

Working with System.Random and threads safely in .NET Core and .NET Framework

Popular DevOps Categories

Docker aws cdk application load balancer AWS CDK Application security AWS CDK application Application Load Balancers with DevOps Guru Auto scale group Automation Autoscale EC2 Autoscale VPC Autoscaling AWS Azure DevOps Big Data BigQuery CAMS DevOps Containers Data Observability Frequently Asked Devops Questions in Interviews GCP Large Table Export GCP Serverless Dataproc DB Export GTmetrix Page Speed 100% Google Page Speed 100% Healthy CI/CD Pipelines How to use AWS Developer Tools IDL web services Infrastructure as code Istio App Deploy Istio Gateways Istio Installation Istio Official Docs Istio Service Istio Traffic Management Java Database Export with GCP Jenkin K8 Kubernetes Large DB Export GCP Linux MSSQL March announcement MySQL Networking Popular DevOps Tools PostgreSQL Puppet Python Database Export with GCP Python GCP Large Table Export Python GCP Serverless Dataproc DB Export Python Postgres DB Export to BigQuery Sprint Top 100 Devops Questions TypeScript Client Generator anti-patterns of DevOps application performance monitoring (APM) aws amplify deploy blazor webassembly aws cdk application load balancer security group aws cdk construct example aws cdk l2 constructs aws cdk web application firewall aws codeguru reviewer cli command aws devops guru performance management aws service catalog best practices aws service catalog ci/cd aws service catalog examples azure Devops use cases azure devops whitepaper codeguru aws cli deploy asp.net core blazor webassembly devops guru for rds devops guru rds performance devops project explanation devops project ideas devops real time examples devops real time scenarios devops whitepaper aws docker-compose.yml health aware ci/cd pipeline example host and deploy asp.net core blazor webassembly on AWS scalable and secure CI/CD pipelines security vulnerabilities ci cd pipeline security vulnerabilities ci cd pipeline aws smithy code generation smithy server generator
Show more