Install Prometheus Operator
This is the helper that will extend Kubernetes API, and help us to deploy monitoring.
Prometheus Operator
We are going to download the original Prometheus Operator from git, and do just one change. We are going to change the namespace in its configs.
root@control01:~# cd
root@control01:~# mkdir prometheus-operator
root@control01:~# cd prometheus-operator
root@control01:~/prometheus-operator# wget https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/master/bundle.yaml
# Check current setting for namespaces in bundle.yaml
root@control01:~/prometheus-operator# grep 'namespace: default' bundle.yaml
namespace: default
namespace: default
namespace: default
namespace: default
#We will change that to monitoring:
root@control01:~/prometheus-operator# sed -i 's/namespace: default/namespace: monitoring/g' bundle.yaml
#Check again:
root@control01:~/prometheus-operator# grep 'namespace: ' bundle.yaml
a `namespace: <object namespace>` matcher.' <-- Ignore this
namespace: monitoring
namespace: monitoring
namespace: monitoring
namespace: monitoring
Also create the namespace monitoring
itself:
kubectl create namespace monitoring
Now apply bundle.yaml
to your Kubernetes cluster:
root@control01:~/prometheus_operator# kubectl apply --server-side -f bundle.yaml
customresourcedefinition.apiextensions.k8s.io/alertmanagerconfigs.monitoring.coreos.com serverside-applied
customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com serverside-applied
customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com serverside-applied
customresourcedefinition.apiextensions.k8s.io/probes.monitoring.coreos.com serverside-applied
customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com serverside-applied
customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com serverside-applied
customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com serverside-applied
customresourcedefinition.apiextensions.k8s.io/thanosrulers.monitoring.coreos.com serverside-applied
clusterrolebinding.rbac.authorization.k8s.io/prometheus-operator serverside-applied
clusterrole.rbac.authorization.k8s.io/prometheus-operator serverside-applied
deployment.apps/prometheus-operator serverside-applied
serviceaccount/prometheus-operator serverside-applied
service/prometheus-operator serverside-applied
This has created a bunch of custom resource definitions
, which now extends our Kubernetes API and deploys one prometheus-operator
into the namespace monitoring
. Also created is the service account
for this deployment, and service
.
Check if they are deployed; it can take a few minutes to come up.
root@control01:~/prometheus_operator# kubectl get pods -n monitoring
NAME READY STATUS RESTARTS AGE
prometheus-operator-5ff445f5c8-pn8xw 1/1 Running 0 93s
Before we deploy the actual Prometheus instance, we should first prepare the service monitors. I mean, it doesn't really matter, but you will have to tell Prometheus which service monitors to scrape. Therefore, it’s better to have them ready first.
Continue with Service Monitors