-
paulfantom authored
Signed-off-by:
paulfantom <pawel@krupa.net.pl>
paulfantom authoredSigned-off-by:
paulfantom <pawel@krupa.net.pl>
kube-prometheus
Note that everything is experimental and may change significantly at any time.
This repository collects Kubernetes manifests, Grafana dashboards, and Prometheus rules combined with documentation and scripts to provide easy to operate end-to-end Kubernetes cluster monitoring with Prometheus using the Prometheus Operator.
The content of this project is written in jsonnet. This project could both be described as a package as well as a library.
Components included in this package:
- The Prometheus Operator
- Highly available Prometheus
- Highly available Alertmanager
- Prometheus node-exporter
- Prometheus Adapter for Kubernetes Metrics APIs
- kube-state-metrics
- Grafana
This stack is meant for cluster monitoring, so it is pre-configured to collect metrics from all Kubernetes components. In addition to that it delivers a default set of dashboards and alerting rules. Many of the useful dashboards and alerts come from the kubernetes-mixin project, similar to this project it provides composable jsonnet as a library for users to customize to their needs.
Warning
If you are migrating from release-0.7
branch or earlier please read what changed and how to migrate in our guide.
Table of contents
-
kube-prometheus
- Warning
- Table of contents
- Prerequisites
- Compatibility
- Quickstart
- Customizing Kube-Prometheus
- Update from upstream project
- Configuration
-
Customization Examples
- Cluster Creation Tools
- Internal Registry
- NodePorts
- Prometheus Object Name
- node-exporter DaemonSet namespace
- Alertmanager configuration
- Adding additional namespaces to monitor
- Monitoring all namespaces
- Static etcd configuration
- Pod Anti-Affinity
- Stripping container resource limits
- Customizing Prometheus alerting/recording rules and Grafana dashboards
- Exposing Prometheus/Alermanager/Grafana via Ingress
- Setting up a blackbox exporter
- Minikube Example
- Continuous Delivery
- Troubleshooting
- Contributing
- License
Prerequisites
You will need a Kubernetes cluster, that's it! By default it is assumed, that the kubelet uses token authentication and authorization, as otherwise Prometheus needs a client certificate, which gives it full access to the kubelet, rather than just the metrics. Token authentication and authorization allows more fine grained and easier access control.
This means the kubelet configuration must contain these flags:
-
--authentication-token-webhook=true
This flag enables, that aServiceAccount
token can be used to authenticate against the kubelet(s). This can also be enabled by setting the kubelet configuration valueauthentication.webhook.enabled
totrue
. -
--authorization-mode=Webhook
This flag enables, that the kubelet will perform an RBAC request with the API to determine, whether the requesting entity (Prometheus in this case) is allowed to access a resource, in specific for this project the/metrics
endpoint. This can also be enabled by setting the kubelet configuration valueauthorization.mode
toWebhook
.
This stack provides resource metrics by deploying the Prometheus Adapter. This adapter is an Extension API Server and Kubernetes needs to be have this feature enabled, otherwise the adapter has no effect, but is still deployed.
minikube
To try out this stack, start minikube with the following command:
$ minikube delete && minikube start --kubernetes-version=v1.20.0 --memory=6g --bootstrapper=kubeadm --extra-config=kubelet.authentication-token-webhook=true --extra-config=kubelet.authorization-mode=Webhook --extra-config=scheduler.address=0.0.0.0 --extra-config=controller-manager.address=0.0.0.0
The kube-prometheus stack includes a resource metrics API server, so the metrics-server addon is not necessary. Ensure the metrics-server addon is disabled on minikube:
$ minikube addons disable metrics-server
Compatibility
Kubernetes compatibility matrix
The following versions are supported and work as we test against these versions in their respective branches. But note that other versions might work!
kube-prometheus stack | Kubernetes 1.18 | Kubernetes 1.19 | Kubernetes 1.20 | Kubernetes 1.21 |
---|---|---|---|---|
release-0.5 |
![]() |
✗ | ✗ | ✗ |
release-0.6 |
✗ | ![]() |
✗ | ✗ |
release-0.7 |
✗ | ![]() |
![]() |
✗ |
release-0.8 |
✗ | ✗ | ![]() |
![]() |
HEAD |
✗ | ✗ | ![]() |
![]() |
Quickstart
Note: For versions before Kubernetes v1.20.z refer to the Kubernetes compatibility matrix in order to choose a compatible branch.
This project is intended to be used as a library (i.e. the intent is not for you to create your own modified copy of this repository).
Though for a quickstart a compiled version of the Kubernetes manifests generated with this library (specifically with example.jsonnet
) is checked into this repository in order to try the content out quickly. To try out the stack un-customized run:
- Create the monitoring stack using the config in the
manifests
directory:
# Create the namespace and CRDs, and then wait for them to be available before creating the remaining resources
kubectl create -f manifests/setup
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.
- And to teardown the stack:
kubectl delete --ignore-not-found=true -f manifests/ -f manifests/setup
Access the dashboards
Prometheus, Grafana, and Alertmanager dashboards can be accessed quickly using kubectl port-forward
after running the quickstart via the commands below. Kubernetes 1.10 or later is required.
Note: There are instructions on how to route to these pods behind an ingress controller in the Exposing Prometheus/Alermanager/Grafana via Ingress section.
Prometheus
$ kubectl --namespace monitoring port-forward svc/prometheus-k8s 9090
Then access via http://localhost:9090
Grafana
$ kubectl --namespace monitoring port-forward svc/grafana 3000
Then access via http://localhost:3000 and use the default grafana user:password of admin:admin
.
Alert Manager
$ kubectl --namespace monitoring port-forward svc/alertmanager-main 9093
Then access via http://localhost:9093
Customizing Kube-Prometheus
This section:
- describes how to customize the kube-prometheus library via compiling the kube-prometheus manifests yourself (as an alternative to the Quickstart section).
- still doesn't require you to make a copy of this entire repository, but rather only a copy of a few select files.
Installing
The content of this project consists of a set of jsonnet files making up a library to be consumed.
Install this library in your own project with jsonnet-bundler (the jsonnet package manager):
$ mkdir my-kube-prometheus; cd my-kube-prometheus
$ jb init # Creates the initial/empty `jsonnetfile.json`
# Install the kube-prometheus dependency
$ jb install github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus@release-0.7 # Creates `vendor/` & `jsonnetfile.lock.json`, and fills in `jsonnetfile.json`
$ wget https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/release-0.7/example.jsonnet -O example.jsonnet
$ wget https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/release-0.7/build.sh -O build.sh
jb
can be installed withgo get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
An e.g. of how to install a given version of this library:
jb install github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus@release-0.7
In order to update the kube-prometheus dependency, simply use the jsonnet-bundler update functionality:
$ jb update
Compiling
e.g. of how to compile the manifests: ./build.sh example.jsonnet