Tutorial – Deploying Prometheus Monitoring in Kubernetes Cluster
There are three ways to deploy Prometheus in a Kubernetes Cluster:
- Creating all configuration YAML files yourself and execute them in the right order.
- Using an operator (which is like a manager of all Prometheus components).
- Using Helm chart to deploy operator.
In this tutorial we will deploy Prometheus in a local Kubernetes Cluster using the third method which is using Helm chart to deploy the Prometheus Operator. This helm chart that is maintained by the helm community itself and is the most efficient and hassle free way of using Prometheus in any Cluster. In this demo, Helm will do the initial setup and Operator will then manage the running Prometheus setup.
Step 1: Creating a Kubernetes Cluster
You can skip this step if you already have a Kubernetes Cluster running in your machine. But in case you don’t have a Cluster running enter the following command to create Kubernetes locally using Minikube:
minikube start
Minikube is a one-node Kubernetes cluster where master processes and work processes both run on one node.
Step 2: Installing Helm
You can install Helm if haven’t already. For Ubuntu, run the following script in order to
curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
sudo apt-get install apt-transport-https --yes
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm
Step 3: Adding the Prometheus repository
Let’s start with adding the Prometheus repository using by entering the following command:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
And then update the repository by entering the following command:
helm repo update
Following message with appear if the Prometheus repository is added via Helm and updated.
Step 4: Installing Prometheus
Enter the following command to install Prometheus using default values:
helm install prometheus prometheus-community/prometheus
You will get a similar output and Prometheus will be installed in the Cluster.
Step 5: Checking all the resources installed
Now that Prometheus is installed in our cluster, we can check all the resources that were installed by the following command:
kubectl get all
And this will give you the list of all the deployed Kubernetes resources:
Step 6: Expose the “prometheus-server” Service
Now that Prometheus is installed in your cluster, we can you it to monitor our cluster. In order to open the Prometheus dashboard on our browser, we need to expose the “prometheus-server” Service since it is currently set as a ClusterIP.
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-ext
This will expose “prometheus-server” Service to port 9090. It check it in our browser, enter the following command, this command will generate the URL for our Prometheus application.
minikube service prometheus-server-ext
And you will get the following dashboard ready:
And with that we have successfully installed Prometheus on our local Kubernetes Cluster using Helm. Prometheus is running inside the cluster and we can access it using a browser/URL.
Kubernetes Prometheus
With modern DevOps becoming more and more complex, monitoring and alerting stakeholders has become even more crucial for any microservice, and Prometheus is a tool to do the same. Prometheus is a completely open-sourced tool created to monitor highly dynamic container environments like Kubernetes, Docker Swarm, etc. However, it can also be used in a traditional non-container infrastructure where you have just bare servers with applications deployed directly on them. In this article, we will learn what prometheus is. We will see why Prometheus is so important in such infrastructure. And what are some of its use cases?
Table of Content
- What is Prometheus Monitoring?
- Why use Prometheus for Kubernetes monitoring?
- Prometheus Architecture
- Key Terminologies
- Tutorial – Deploying Prometheus Monitoring in Kubernetes Cluster
- Step 1: Creating a Kubernetes Cluster
- Step 2: Installing Helm
- Step 3: Adding the Prometheus repository
- Step 4: Installing Prometheus
- Step 5: Checking all the resources installed
- Step 6: Expose the “prometheus-server” Service
- Advantages of Prometheus
- How Prometheus compares to other Kubernetes monitoring tools
- The challenges of Prometheus scaling and monitoring
- Increased management overhead for SREs and platform teams
- Prometheus Kubernetes Service Discovery
- Conclusion
- Kubernetes Prometheus – FAQ’s