In this blog we will see how to install Prometheus in Kubernetes cluster and view the metrics of Kubernetes Cluster.

Prometheus : It is an open source tool which used to collect real time metrics and modern alerting.

Requirements :

1. Kubernetes cluster
2. helm

My Environment details,

Kubernetes version : 1.15.3
Helm version : 2.16.8
Single node kubernetes cluster

Step 1:

Add official Charts repository in helm,

# helm repo add stable https://kubernetes-charts.storage.googleapis.com

To list the repository list in helm,

#  helm repo list



Step 2 :

Install Prometheus by helm,

#  helm install stable/prometheus --name prometheus

If you need to deploy prometheus in separate namespace you can add, --namespace namespace-name in the above command at the end.




To check the helm installed application,

# helm list



Wait for few minutes until the pods are getting created.

Now check the pods status of prometheus

# kubectl get pods



when we check the status of the pod, we can see prometheus-altermanager and prometheus-server pods are still in pending state its due to persistent volume.when I checked the persistent volume claim status it is in pending,

# kubectl get pvc



To overcome this issue, execute this below command,

# mkdir /mnt/prometheusvol{1,2}

Note: execute above mkdir command in all the nodes in the cluster.

Then execute in master server,

# kubectl create -f - <<EOF
kind: PersistentVolume
apiVersion: v1
metadata:
  name: prometheusvol1
spec:
  storageClassName:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/prometheusvol1"
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: prometheusvol2
spec:
  storageClassName:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/prometheusvol2"
EOF

Now check the pvc and pod status,



Now everything is working fine.

Step 3:

Access Prometheus,

To access prometheus edit prometheus-server service and change ClusterIP to NodePort.

# kubectl get svc

# kubectl edit svc prometheus-server



Now we get the port to access prometheus in browser,here my prometheus server port is 32114. I will go to browser,

URL : Kubernetes IP:Portnumber

http://192.168.108.4:32114


I can access the Prometheus in browser. From the Menu go to status > Targets to check the status of all Kubernetes applications.



I can see the metrics for kubernetes events in prometheus Graph,



That's all we have installed Prometheus successfully in Kubernetes cluster and can view the metrics.


Post a Comment

Previous Post Next Post