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

Project - Real Time Monitoring Project

This document provides steps to set up real time monitoring of a Kubernetes cluster using Prometheus and Grafana. It covers setting up an EKS cluster, installing Prometheus, Grafana and configuring dashboards to monitor the cluster and deploying a sample Java application for testing.

Uploaded by

Karan Karan
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)
247 views

Project - Real Time Monitoring Project

This document provides steps to set up real time monitoring of a Kubernetes cluster using Prometheus and Grafana. It covers setting up an EKS cluster, installing Prometheus, Grafana and configuring dashboards to monitor the cluster and deploying a sample Java application for testing.

Uploaded by

Karan Karan
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/ 12

REAL TIME MONITORING HANDSON

Prometheus and Grafana Dashboard on EKS Cluster using Helm Chart

l
lo
x.
le
ip
.a

Step 1 – Setup EC2 Instance


Instance Type as t2.medium
AMIs as Ubuntu
US-EAST-1
w
w
w

Step 1.1 – Create the IAM role having full access

Get more free courses at www.aiplex.lol


Go to IAM -> Create role -> Select EC2 -> Give Full admin access

l
lo
Step 1.2 – Attach the IAM role having full access

x.
Go to EC2 -> Click on Actions on the left hand side -> Security -> Modify
IAM role

le
ip
.a
w
w

Step 2 - Install AWS CLI and Configure


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

"awscliv2.zip"

sudo apt install unzip


unzip awscliv2.zip
sudo ./aws/install

Get more free courses at www.aiplex.lol


Step 3 - Install and Setup Kubectl
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

l
lo
sudo mv ./kubectl /usr/local/bin

x.
kubectl version

kubectl version --short

le
Step 4 - Install and Setup eksctl
ip
curl --silent --location
"https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$
(uname -s)_amd64.tar.gz" | tar xz -C /tmp
.a

sudo mv /tmp/eksctl /usr/local/bin


w

eksctl version
w

Step 5 - Install Helm chart


w

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

Get more free courses at www.aiplex.lol


helm version

Step 6 - Creating an Amazon EKS cluster using eksctl

1. Name of the cluster : --eks2

2. Version of Kubernetes : --version 1.24

l
lo
3. Region : --region us-east-1

4. Nodegroup name/worker nodes : --nodegroup-name worker-nodes

x.
5. Node Type : --nodegroup-type t2.medium

6. Number of nodes: --nodes 2


le
7. Minimum Number of nodes: --nodes-min 2

8. Maximum Number of nodes: --nodes-max 3


ip
eksctl create cluster --name eks2 --version 1.24 --region us-east-1
--nodegroup-name worker-nodes --node-type t2.medium --nodes 2
.a

--nodes-min 2 --nodes-max 3
w
w

Step 6.1 - IF ANY ERROR:


w

aws eks update-kubeconfig --region <region-code> --name <cluster-name>

Step 7 - Installing the Kubernetes Metrics Server

Get more free courses at www.aiplex.lol


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

Step 7.1 - Verify that the metrics-server deployment is running the


desired number of pods with the following command

kubectl get deployment metrics-server -n kube-system

l
lo
Step 8 - Install Prometheus

Now install the Prometheus using the helm chart.

x.
Add Prometheus helm chart repository

le
helm repo add prometheus-community
https://prometheus-community.github.io/helm-charts
ip
Step 8.1 - Update helm chart repository

helm repo update


.a

helm repo list

Step 8.2 Create prometheus namespace


w

kubectl create namespace prometheus


w

Step 8.3 - Install Prometheus

helm install prometheus prometheus-community/prometheus --namespace


w

prometheus --set alertmanager.persistentVolume.storageClass="gp2"


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

Get more free courses at www.aiplex.lol


l
Step 9 - Create IAM OIDC Provider

lo
Your cluster has an OpenID Connect (OIDC) issuer URL associated with it. To
use AWS Identity and Access Management (IAM) roles for service accounts,

x.
an IAM OIDC provider must exist for your cluster's OIDC issuer URL.

oidc_id=$(aws eks describe-cluster --name eks2 --region us-east-1 --query


le
"cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)

aws iam list-open-id-connect-providers | grep $oidc_id | cut -d "/" -f4


ip
eksctl utils associate-iam-oidc-provider --cluster eks2 --approve --region
.a

us-east-1
w

Step 10 – Create iamserviceaccount with role


w

eksctl create iamserviceaccount --name ebs-csi-controller-sa --namespace


kube-system --cluster eks2 --attach-policy-arn
w

arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy --approve
--role-only --role-name AmazonEKS_EBS_CSI_DriverRole --region us-east-1

Get more free courses at www.aiplex.lol


Step 10.1 - Then attach ROLE to eks by running the following command

Enter your account ID and cluster name.

l
lo
eksctl create addon --name aws-ebs-csi-driver --cluster eks2
--service-account-role-arn
arn:aws:iam::164297528770:role/AmazonEKS_EBS_CSI_DriverRole --force

x.
--region us-east-1

le
ip
Step 10.2 - kubectl get pods -n prometheus
.a
w
w

Step 10.3 - View the Prometheus dashboard by forwarding the


w

deployment ports

kubectl port-forward deployment/prometheus-server 9090:9090 -n


prometheus

Get more free courses at www.aiplex.lol


Step 10.4 - Open different browser and connect to your EC2 instance and
run curl localhost:9090/graph

Step 11 - Install Grafana


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

l
lo
helm repo update

x.
Step 11.1 - Create a namespace Grafana

kubectl create namespace grafana

le
ip
.a

Step 11.2 - Install the Grafana

helm install grafana grafana/grafana --namespace grafana --set


w

persistence.storageClassName="gp2" --set persistence.enabled=true --set


adminPassword='EKS!sAWSome' --set service.type=LoadBalancer
w

This command will create the Grafana service with an external load
balancer to get the public view.
w

Step 11.3 - Verify the Grafana installation by using the


following kubectl command

kubectl get pods -n grafana

Get more free courses at www.aiplex.lol


kubectl get service -n grafana

l
lo
Step 11.4 - Copy the EXTERNAL-IP and paste in browser

x.
Password you mentioned as EKS!sAWSome while creating Grafana

le
ip
.a
w
w

Step 11.5 - Add the Prometheus as the datasource to Grafana


w

Go to Grafana Dashboard -> Add the Datasource -> Select the Prometheus

Get more free courses at www.aiplex.lol


l
lo
x.
le
Step 11.6 - Configure the endpoints of Prometheus and save
ip
URL - http://prometheus-server.prometheus.svc.cluster.local
.a
w
w
w

Get more free courses at www.aiplex.lol


Step 11.6 - Import Grafana dashboard from Grafana Labs

Now we have set up everything in terms of Prometheus and Grafana. For


the custom Grafana Dashboard, we are going to use the open source
grafana dashboard. For this session, I am going to import a dashboard 6417

l
lo
Go to left side -> click on dashboards -> Click on New -> Import

x.
le
ip
.a

Load and select the source as Prometheus


w
w
w

Step 12 – Visualise the java application

Get more free courses at www.aiplex.lol


l
lo
x.
le
Step 13 - Deploy a Java application and monitor it on Grafana
ip
git clone
https://github.com/praveen1994dec/kubernetes_java_deployment.git
.a

cd /kubernetes_java_deployment/Kubernetes/

kubectl apply -f shopfront-service.yaml


kubectl get deployment
w

kubectl get pods


w

kubectl logs shopfront-7868468c56-4r2kk -c shopfront


w

Step 14 - Clean Up

eksctl delete cluster --name eks2 --region us-east-1

Get more free courses at www.aiplex.lol

You might also like