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

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
  name: prometheusvol1
    storage: 5Gi
    - ReadWriteOnce
    path: "/mnt/prometheusvol1"
kind: PersistentVolume
apiVersion: v1
  name: prometheusvol2
    storage: 10Gi
    - ReadWriteOnce
    path: "/mnt/prometheusvol2"

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

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