Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Last active July 28, 2024 05:13
Show Gist options
  • Save j-thepac/d9192c6bc13167ce0a11a5b77f8ffd36 to your computer and use it in GitHub Desktop.
Save j-thepac/d9192c6bc13167ce0a11a5b77f8ffd36 to your computer and use it in GitHub Desktop.
Kubernetes ,Promethus and Grafana

Kubernetes with Prometheus and Grafane

  • Helm Chart : Package installer for kubernetes

  • Prometheus: Open-source monitoring and alerting toolkit ( A Prometheus deployment needs dedicated storage space to store scraping data)

  • Grafana : visualization, and observability in Prometheus

1. Pre-Req

minikube start 		# minikube start --memory='12g' --cpus='4' -n 3
kubectl config view | grep namespace #get current namespace
kubectl cluster-info
minikube addons list

# Extra 
		minikube addons enable csi-hostpath-driver	 
		# Enable dedicated storage space to store scraping data  
		kubectl patch storageclass csi-hostpath-sc -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
		kubectl patch storageclass standard -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'

2. helm:

	Install helm - https://helm.sh/docs/intro/install/
	kubectl get ns
	kubectl create namespace monitoring
	kubectl get deployments --namespace=monitoring
	kubectl get pods --namespace=monitoring
	kubectl get configmap -n monitoring
	helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
	helm repo list
	helm repo update

3. prometheus:

	helm install prometheus prometheus-community/prometheus --namespace monitoring
	kubectl get pods -n monitoring
	kubectl expose service prometheus-server --namespace monitoring --type=NodePort --target-port=9090 --name=prometheus-server-ext
	minikube ip
	kubectl get svc -n monitoring
	#Prometheus Server UI = minikubeIP + 30333 [prometheus-server-ext port] eg : 192.168.49.2:30333

4. grafana

	helm repo add grafana https://grafana.github.io/helm-charts
	helm install grafana grafana/grafana --namespace monitoring
	#run the command in the display to get password -SCaxM0KE4GRzxxxx
	
	kubectl expose service grafana --namespace monitoring --type=NodePort --target-port=3000 --name=grafana-ext
	kubectl get svc -n monitoring
	#Grafana  UI = minikubeIP + 32084 [grafana-ext ] 

5. Integrate Promethus to Grafana

	kubectl get svc -n monitoring #copy PORT
	Open URL Grafana = minikubeIP + 32084 [grafana-ext port]
	usn = admin , password from output command during installation	
	Home > Add first Datasource > prometheus >Add URL =  http://prometheusURL >save and test
	Home > Dashboard > New > Import > Enter 3662 >Load
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment