0% found this document useful (0 votes)
184 views

Prometheus and Grafana For EKS Cluster

This document provides instructions for installing and configuring various tools like AWS CLI, kubectl, eksctl, Helm, Prometheus, and Grafana on an Amazon EC2 instance to monitor an Amazon EKS cluster. It explains how to install the tools using commands like curl, unzip, and yum. It also provides steps to configure AWS CLI, install Prometheus and Grafana using Helm charts, and access the Grafana dashboard.

Uploaded by

prakash.jeh09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
184 views

Prometheus and Grafana For EKS Cluster

This document provides instructions for installing and configuring various tools like AWS CLI, kubectl, eksctl, Helm, Prometheus, and Grafana on an Amazon EC2 instance to monitor an Amazon EKS cluster. It explains how to install the tools using commands like curl, unzip, and yum. It also provides steps to configure AWS CLI, install Prometheus and Grafana using Helm charts, and access the Grafana dashboard.

Uploaded by

prakash.jeh09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Install AWS CLI and Configure

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

sudo apt install unzip

unzip awscliv2.zip

sudo ./aws/install

Okay now after installing the AWS CLI, let's configure the AWS CLI so that it can
authenticate and communicate with the AWS environment.

aws configure

Install and Setup Kubectl

Moving forward now we need to set up the kubectl also onto the EC2 instance.

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s


https://storage.googleapis.com/kubernetes-
release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin
kubectl version
Install and Setup eksctl

curl --silent --location


"https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -
s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version

Install Helm chart

$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-


helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh

This way we install all AWS CLI, kubectl, eksctl and Helm.
Follow below steps to install terraform on AmazonLinux.

sudo yum install -y yum-utils shadow-utils


sudo yum-config-manager --add-repo
https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform

Creating an Amazon EKS cluster using terraform

Code available in https://github.com/ksnithya/blue-green.git


git clone https://github.com/ksnithya/blue-green.git
cd blue-green

terraform init
terraform plan
terraform apply
aws eks --region ap-south-1 update-kubeconfig --name eks_cluster_demo

Installing the Kubernetes Metrics Server

kubectl apply -f https://github.com/kubernetes-sigs/metrics-


server/releases/latest/download/components.yaml

kubectl get deployment metrics-server -n kube-system

Install Prometheus

Now we install the Prometheus using the helm chart.

Add Prometheus helm chart repository

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


charts

Update the helm chart repository


helm repo update
helm repo list

Create prometheus namespace

kubectl create namespace Prometheus


Install Prometheus
helm install prometheus prometheus-community/kube-prometheus-stack -n prometheus

View the Prometheus dashboard by forwarding the deployment ports

kubectl port-forward statefulset.apps/prometheus-prometheus-kube-prometheus-


prometheus 9090 -n prometheus &

run curl localhost:9090/graph

Install Grafana

Add the Grafana helm chart repository. Later, Update the helm chart repository.

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


helm repo update

Create a namespace Grafana

kubectl create namespace Grafana


Install the Grafana
helm install grafana grafana/grafana \
--namespace grafana \

--set adminPassword='Venkat@123' \
--set service.type=LoadBalancer

We can change the service of Prometheus to LoadBalance.


kubectl get service/prometheus-kube-prometheus-prometheus -n prometheus -o
yaml>prometheus.yml

[ec2-user@ip-172-31-9-225 blue-green]$ cat prometheus.yml


apiVersion: v1
kind: Service
metadata:

annotations:
meta.helm.sh/release-name: prometheus
meta.helm.sh/release-namespace: prometheus
labels:
app: kube-prometheus-stack-prometheus

app.kubernetes.io/instance: prometheus
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/part-of: kube-prometheus-stack
app.kubernetes.io/version: 55.5.1
chart: kube-prometheus-stack-55.5.1
heritage: Helm
release: prometheus
self-monitor: "true"

name: prometheus-kube-prometheus-prometheus
namespace: prometheus
resourceVersion: "6646"
uid: 0e68febb-a677-49b9-86b6-85602ea04fcc

spec:
ports:
- name: http-web
port: 9090

protocol: TCP
targetPort: 9090
- appProtocol: http
name: reloader-web
port: 8080

protocol: TCP
targetPort: reloader-web
selector:
app.kubernetes.io/name: prometheus

operator.prometheus.io/name: prometheus-kube-prometheus-prometheus
sessionAffinity: None
type: LoadBalancer
status:

loadBalancer: {}
[ec2-user@ip-172-31-9-225 blue-green]$

kubectl replace -f prometheus.yml –force

above command will replace the service to LOadbalancer.


We can access the Graphana using Loadbalancer URL.
http:// ad49ef87dbee742d9a930b9cb301b163-206512672.ap-south-
1.elb.amazonaws.com:80

Now we can add our Prometheus to it.


Home -> connections -> Datasource - > Add
Give name and Prometheus service Loadbalancer URL.
Now we create dashboard.
Home -> dashboard -> New -> Import( we use existing Grafana dashboard)

“6417” dashboard of Kubernetes.


Give name, Select the Prometheus we have created. Then import it.

You might also like