Monitoring EKS cluster through Prometheus and Grafana

Prometheus

Prometheus is a monitoring tool that watches over computer systems and applications, keeping track of their performance and health. It helps identify and alert users about potential issues, ensuring smooth operations in digital environments.

 

Grafana

Grafana is an open-source platform for visualizing and analyzing data. It provides interactive and customizable dashboards that allow users to create, explore, and share insights from various data sources. Grafana is widely used for monitoring and observability, offering flexible visualization options, alerting capabilities, and integration with diverse data storage systems, including databases, time-series databases, and monitoring tools like Prometheus. In essence, Grafana transforms data into meaningful charts and graphs, enhancing the understanding of complex information and facilitating data-driven decision-making.

 

Flow Diagram

 

Steps

Step 1: Installing the Kubernetes Metrics Server

Step 2: Install Prometheus

Step 3: Install Grafana

Step 4: Uninstall Prometheus and Grafana

 

Prometheus:

  • Focus: Data collection and storage
  • Strengths:
    • Highly configurable metrics scraping
    • Powerful query language (PromQL) for analyzing time series data
    • Built-in alerting based on defined thresholds
    • Exporters available for a wide range of applications and services
  • Weaknesses:
    • Limited data visualization capabilities
    • Lacks user-friendly dashboards and interfaces

 

Grafana:

  • Focus: Data visualization and dashboards
  • Strengths:
    • Rich visualization options for various data types, including tables
    • Ability to combine data from multiple sources (including Prometheus)
    • User-friendly interface for creating and managing dashboards
    • Sharing and collaboration features
  • Weaknesses:
    • Doesn’t collect or store data itself
    • Relies on external data sources like Prometheus

Using Tables:

  • Prometheus tables:
    • Generated using PromQL queries
    • Offer raw data values
    • Useful for quick overviews or detailed analysis with PromQL
  • Grafana tables:
    • More flexible and customizable
    • Can present aggregated data and calculations
    • Great for visualizing trends, comparisons, and complex metrics across multiple sources

Choosing the Right Option:

  • Use Prometheus tables: When you need a quick overview of raw data points or want to analyze specific metrics with PromQL.
  • Use Grafana tables: When you need a visual representation of trends, comparisons, or aggregated data across multiple metrics.

 

Flow Diagram

 

 

Step 1: Installing the Kubernetes Metrics Server

Through Prometheus and Grafana, we are monitoring the EKS cluster, please follow the steps on the below page/link, to install and set up the EKS cluster and 3-tier web application on the EKS Cluster.

Deployment of 3-tier web application in AWS EKS through Terraform

 

Then, Follow the below steps from the client machine used for the creation of eks cluster


kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

kubectl get deployment metrics-server -n kube-system

 

The Kubernetes Metrics Server is a component in the Kubernetes ecosystem that is responsible for collecting and exposing resource utilization data from nodes and pods in a cluster. It provides a scalable and efficient way to gather metrics and enables the Kubernetes Horizontal Pod Autoscaler (HPA) to automatically adjust the number of pod replicas based on observed resource metrics.

 

Step 2: Install Prometheus

Attach “AmazonEBSCSIDriverPolicy” policy to the IAM role created for Node group while creating the EKS cluster through Terraform script i.e. noderole

Navigate to IAM >> Roles >> Select “noderole” >> Add permissions >> Attach policy >> select “AmazonEBSCSIDriverPolicy” >> Add permissions

 

 

Managing the Amazon EBS CSI driver as an Amazon EKS add-on:

Navigate to All services >> EKS >> clusters >> select “webapp-dev” >> addon >> get more add ons >> select “Amazon EBS CSI driver” >> select “noderole” >> create

 

 


kubectl create namespace prometheus

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

helm upgrade -i prometheus prometheus-community/prometheus \

--namespace prometheus \

--set alertmanager.persistentVolume.storageClass="gp2",server.persistentVolume.storageClass="gp2"

kubectl get pods -n prometheus

kubectl expose service prometheus-server --type=LoadBalancer --name=prometheus-loadbalancer --port=9090 -n prometheus

 

Accessing Prometheus with its loadbalancer url on port 9090

 

 

Step 3: Install Grafana

a. Copy paste the following in a YAML file, name it grafana.yaml


datasources:
datasources.yaml:
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: http://prometheus-server.prometheus.svc.cluster.local
access: proxy
isDefault: true

 

b. Grab Grafana Helm charts


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

c. Install Grafana

kubectl create namespace grafana

helm install grafana grafana/grafana \

--namespace grafana \

--set persistence.storageClassName="gp2" \

--set persistence.enabled=true \

--set adminPassword='EKS!sAWSome' \

--values grafana.yaml \

--set service.type=LoadBalancer

 

d. Check if Grafana is deployed properly


kubectl get all -n grafana

 

e. Get Grafana ELB url


export ELB=$(kubectl get svc -n grafana grafana -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')

echo "http://$ELB"

 

f. When logging in, use username “admin” and get password by running the following:


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

 

g. Grafana Dashboards for K8s:

Accessing Grafana with its loadbalancer URL

Username: admin

Password: “get from above”

Add dashboard : 3119 and select prometheus

 

 

Step 4: Uninstall Prometheus and Grafana


helm uninstall prometheus --namespace prometheus

helm uninstall grafana --namespace grafana

kubectl delete -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

 

Delete from Amazon console – go to AWS EKS – Add-on – Delete manually added aws-ebs-csi-driver

Delete the load-balancer created for Prometheus manually

 

Leave a Reply

Your email address will not be published. Required fields are marked *