How to Deploy Prometheus Operator to a Kubernetes Cluster

Brightband
4 min readJun 14, 2023

--

Prometheus Helm Operator

Introduction

Prometheus is a popular open-source monitoring and alerting solution, and has over time become an indispensable tool for managing and observing Kubernetes clusters. However, deploying and managing Prometheus properly can be a daunting undertaking and take a lot of effort to support. To simplify this, Prometheus offers a Kubernetes Operator to make deployment simple and easy. If you are unfamiliar with Kubernetes Operators, you can read up on them here. In this article, we will guide you through the step-by-step process of deploying the Prometheus Operator to your Kubernetes cluster, enabling you to effortlessly monitor your applications and infrastructure.

Prerequisites

Before we dive into the deployment process, ensure that you have the following prerequisites set up:

  1. A Kubernetes cluster up and running. Minikube is a good option. You can read about setting up a minikube cluster here.
  2. kubectl, the Kubernetes command-line tool, installed and configured through your favorite package manager.
  3. Helm, a popular Kubernetes manifest manager, installed and configured through your favorite package manager.
  4. Basic knowledge of Kubernetes concepts like pods, deployments, and services. If you are brand new to Kubernetes, check out this article about Kubernetes basics.

Step 1: Installing the Prometheus Operator

The first step is to install the Prometheus Operator on your Kubernetes cluster. Follow these steps:

  • Create a new namespace for Prometheus Operator using the following command:
$ kubectl create namespace monitoring
namespace/monitoring created
  • Add the Prometheus Operator Helm repository:
$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
"prometheus-community" has been added to your repositorieshelm
  • Update the Helm repositories:
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "prometheus-community" chart repository
Update Complete. ⎈Happy Helming!⎈
  • If this is your first time using helm on your cluster, ensure Tiller is installed within your cluster:
$ helm init
$HELM_HOME has been configured at /home/brightband/.helm.

Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.

Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
To prevent this, run `helm init` with the --tiller-tls-verify flag.
For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
  • Install the Prometheus Operator using Helm:
$ helm install prometheus-operator prometheus-community/kube-prometheus-stack -n monitoring
NAME: prometheus-operator
LAST DEPLOYED: Wed Jun 11 18:14:16 2023
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
NOTES:
kube-prometheus-stack has been installed. Check its status by running:
kubectl --namespace monitoring get pods -l "release=prometheus-operator"

Visit https://github.com/prometheus-operator/kube-prometheus for instructions on how to create & configure Alertmanager and Prometheus instances using the Operator.

Step 2: Verifying the Deployment

After installing the Prometheus Operator, verify that the deployment is successful:

  • Check the status of the deployed Prometheus Operator components, ensuring that all of the pods are in “Running” state.
$ kubectl get pods -n monitoring
NAME READY STATUS RESTARTS AGE
alertmanager-prometheus-operator-kube-p-alertmanager-0 2/2 Running 0 87s
prometheus-operator-grafana-75d7c56bff-j9glm 3/3 Running 0 101s
prometheus-operator-kube-p-operator-7dbb446487-rp6vc 1/1 Running 0 101s
prometheus-operator-kube-state-metrics-7cb556579f-mb4hd 1/1 Running 0 101s
prometheus-operator-prometheus-node-exporter-2nbc8 1/1 Running 0 101s
prometheus-operator-prometheus-node-exporter-g6bkj 1/1 Running 0 101s
prometheus-prometheus-operator-kube-p-prometheus-0 2/2 Running 0 86s

Step 3: Accessing Prometheus and Grafana Dashboards

To access the Prometheus and Grafana dashboards, follow these steps:

  • Check the service endpoints of Prometheus and Grafana. This will tell you where these endpoints are exposed to.
$ kubectl get svc -n monitoring
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 3m15s
prometheus-operated ClusterIP None <none> 9090/TCP 3m14s
prometheus-operator-grafana ClusterIP 10.100.144.14 <none> 80/TCP 3m29s
prometheus-operator-kube-p-alertmanager ClusterIP 10.100.177.167 <none> 9093/TCP 3m29s
prometheus-operator-kube-p-operator ClusterIP 10.100.189.8 <none> 443/TCP 3m29s
prometheus-operator-kube-p-prometheus ClusterIP 10.100.45.176 <none> 9090/TCP 3m29s
prometheus-operator-kube-state-metrics ClusterIP 10.100.89.239 <none> 8080/TCP 3m29s
prometheus-operator-prometheus-node-exporter ClusterIP 10.100.249.162 <none> 9100/TCP 3m29s
  • Use port forwarding to access the Prometheus dashboard locally:
$ kubectl port-forward svc/prometheus-operator-kube-p-prometheus -n monitoring 9090:9090
Forwarding from 127.0.0.1:9090 -> 9090
Forwarding from [::1]:9090 -> 9090
  • Access the Prometheus dashboard by opening http://localhost:9090 in your browser.
  • Similarly, we can access the Grafana dashboard using port forwarding:
$ kubectl port-forward svc/prometheus-operator-grafana -n monitoring 3000:80
Forwarding from 127.0.0.1:3000 -> 3000
Forwarding from [::1]:3000 -> 3000
  • Access the Grafana dashboard by opening http://localhost:3000 in your browser. Use the default credentials (admin/admin) to log in.

Conclusion

Now that you have your Prometheus Operator setup correctly and running in your cluster, you can begin to leverage the power of custom metrics and alerts. To learn more about how to get pushing metrics to Prometheus from your applications, you can read more here.

--

--

Brightband

Brightband is an AI Based Cloud Optimization Service & Open Source Debugging Tool | www.brightband.io