Prometheus is an open-source system monitoring and alerting toolkit that is highly suitable for collecting data from your Kubernetes cluster.
Prometheus is particularly useful when combined with Grafana or the Lens application; both make it easier to visualize your Kubernetes data. In the case of Lens, after installing Prometheus, Lens automatically detects the Prometheus installation, requiring no additional configuration.
In this tutorial, we explain how to install Prometheus on a Kubernetes cluster using the Operator version of Prometheus. A Kubernetes Operator automatically handles parts of the deployment and configuration of software, in this case, Prometheus and its associated components.
For the steps in this tutorial, we use the Helm package manager. If you haven't already, install the Helm package manager on your Kubernetes cluster.
Step 1
First, create a new namespace for Prometheus:
kubectl create ns prometheus
Step 2
Add the official Prometheus Helm repository to your cluster:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update
Step 3
Next, install the Prometheus Operator in the Prometheus namespace using the following command:
helm install prometheus-operator prometheus-community/kube-prometheus-stack --namespace prometheus
- helm install installs the chart.
- prometheus-operator is the name we give to the Helm release, making it easier to identify compared to "kube-prometheus-stack."
- prometheus-community/kube-prometheus-stack is the repository and chart being installed.
- --namespace prometheus installs the Helm release in the Prometheus namespace.
- Optionally, you can use your own values.yaml file to make changes and refer to it during installation using the addition -f values.yaml (see our documentation on editing Helm charts for installation for more options).
You will see an output similar to the following:
LAST DEPLOYED: Mon Jun 19 11:11:11 2023
NAMESPACE: prometheus
REVISION: 1
NOTES:
kube-prometheus-stack has been installed. Check its status by running:
kubectl --namespace prometheus 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.
NAME READY STATUS RESTARTS AGE
prometheus-operator-kube-state-metrics-69b8c745bd-cvmvg 1/1 Running 0 23s
prometheus-operator-prometheus-node-exporter-8hfww 1/1 Running 0 24s
prometheus-operator-prometheus-node-exporter-9757r 1/1 Running 0 24s
prometheus-operator-prometheus-node-exporter-w6nk9 1/1 Running 0 24s
With that, the installation of Prometheus is complete! Visit https://github.com/prometheus-operator/kube-prometheus if you want to work solely with Prometheus or refer to our Grafana or Lens tutorial if you want to combine Prometheus with either of them.
You can retrieve information about your Helm release using the following command:
helm list -n prometheus