The easiest way of starting with the Prometheus Operator is by deploying it as part of kube-prometheus. kube-prometheus deploys the Prometheus Operator and already schedules a Prometheus called prometheus-k8s with alerts and rules by default.
Note: the Kubernetes compatibility matrix in order to choose a compatible branch.
Get the kube-prometheus project
For a quick start we are going to deploy a compiled version of the Kubernetes manifests.
You can either clone the kube-prometheus from GitHub
git clone https://github.com/prometheus-operator/kube-prometheus.git
Once you have the files on your machine change into the project’s root directory.
Deploy kube-prometheus
# Create the namespace and CRDs, and then wait for them to be availble before creating the remaining resources
kubectl create -f manifests/setup
# Wait until the "servicemonitors" CRD is created. The message "No resources found" means success in this context.
until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done
kubectl create -f manifests/
We create the namespace and CustomResourceDefinitions first to avoid race conditions when deploying the monitoring components. Alternatively, the resources in both folders can be applied with a single command
kubectl create -f manifests/setup -f manifests
but it may be necessary to run the command multiple times for all components to be created successfullly.
Access Prometheus
Prometheus, Alertmanager, and Grafana dashboards can be accessed quickly using kubectl port-forward after running the quickstart via the commands below.
You can also learn how to expose via an Ingress
kubectl --namespace monitoring port-forward svc/prometheus-k8s 9090
Open Prometheus on localhost:9090 in your browser.
Check out the alerts and rules pages with the pre-configured rules and alerts! This Prometheus is supposed to monitor your Kubernetes cluster and make sure to alert you if there’s a problem with it.
For your own applications we recommend running one or more other instances.
Access Alertmanager
kubectl --namespace monitoring port-forward svc/alertmanager-main 9093
Open Alertmanager on localhost:9093 in your browser.
Access Grafana
kubectl --namespace monitoring port-forward svc/grafana 3000
Open Grafana on localhost:3000 in your browser. You can login with the username admin and password admin.
Remove kube-prometheus
If you’re done experimenting with kube-prometheus and the Prometheus Operator you can simply teardown the deployment by running:
kubectl delete --ignore-not-found=true -f manifests/ -f manifests/setup