6.6 KiB
Migration guide from release-0.7 and earlier
Why?
Thanks to our community we identified a lot of short-commings of previous design, varying from issues with global state to UX problems. Hoping to fix at least part of those issues we decided to do a complete refactor of the codebase.
Overview
Breaking Changes
- global
_configobject is removed and the newvaluesobject is a partial replacement imageReposfield was removed and the project no longer tries to compose image strings. Use$.values.common.imagesto override default images.- prometheus alerting and recording rules are split into multiple
PrometheusRuleobjects - kubernetes control plane ServiceMonitors and Services are now part of the new
kubernetesControlPlanetop-level object instead ofprometheusobject jsonnet/kube-prometheus/kube-prometheus.libsonnetfile was renamed tojsonnet/kube-prometheus/main.libsonnetand slimmed down to bare minimumjsonnet/kube-prometheus/kube-prometheus*-.libsonnetfiles were move either tojsonnet/kube-prometheus/addons/orjsonnet/kube-prometheus/platforms/depending on the feature they provided- all component libraries are now function- and not object-based
- monitoring-mixins are included inside each component and not globally.
prometheusRules,prometheusAlerts, andgrafanaDashboardsare accessible only per component viamixinobject (ex.$.alertmanager.mixin.prometheusAlerts) - default repository branch changed from
mastertomain - labels on resources have changes,
kubectl applywill not work correctly due to those field being immutable. Deleting the resource first before applying is a workaround if you are using the kubectl CLI. (This only applies toDeploymentsandDaemonSets.)
New Features
- concept of
addons,components, andplatformswas introduced - all main
componentsare now represented internally by a function with default values and required parameters (see #Component-configuration for more information) $.valuesholds main configuration parameters and should be used to set basic stack configuration.- common parameters across all
componentsare stored now in$.values.common - removed dependency on deprecated ksonnet library
Details
Components, Addons, Platforms
Those concepts were already present in the repository but it wasn't clear which file is holding what. After refactoring we categorized jsonnet code into 3 buckets and put them into separate directories:
components- main building blocks for kube-prometheus, written as functions responsible for creating multiple objects representing kubernetes manifests. For example all objects for node_exporter deployment are bundled incomponents/node_exporter.libsonnetlibraryaddons- everything that can enhance kube-prometheus deployment. Those are small snippets of code adding a small feature, for example adding anti-affinity to pods viaaddons/anti-affinity.libsonnet. Addons are meant to be used in object-oriented way likelocal kp = (import 'kube-prometheus/main.libsonnet') + (import 'kube-prometheus/addons/all-namespaces.libsonnet')platforms- currently those areaddonsspecialized to allow deploying kube-prometheus project on a specific platform.
Component configuration
Refactoring main components to use functions allowed us to define APIs for said components. Each function has a default set of parameters that can be overridden or that are required to be set by a user. Those default parameters are represented in each component by defaults map at the top of each library file, for example in node_exporter.libsonnet.
This API is meant to ease the use of kube-prometheus as parameters can be passed from a JSON file and don't need to be in jsonnet format. However, if you need to modify particular parts of the stack, jsonnet allows you to do this and we are also not restricting such access in any way. An example of such modifications can be seen in any of our addons, like the addons/anti-affinity.libsonnet one.
Mixin integration
Previously kube-prometheus project joined all mixins on a global level. However with a wider adoption of monitoring mixins this turned out to be a problem, especially apparent when two mixins started to use the same configuration field for different purposes. To fix this we moved all mixins into their own respective components:
- alertmanager mixin ->
alertmanager.libsonnet - kubernetes mixin ->
k8s-control-plane.libsonnet - kube-state-metrics mixin ->
kube-state-metrics.libsonnet - node_exporter mixin ->
node_exporter.libsonnet - prometheus and thanos sidecar mixins ->
prometheus.libsonnet - prometheus-operator mixin ->
prometheus-operator.libsonnet - kube-prometheus alerts and rules ->
components/mixin/custom.libsonnet
etcd mixin is a special case as we add it inside an
addoninaddons/static-etcd.libsonnet
This results in creating multiple PrometheusRule objects instead of having one giant object as before. It also means each mixin is configured separately and accessing mixin objects is done via $.<component>.mixin.
Examples
All examples from examples/ directory were adapted to the new codebase. Please take a look at them for guideance
Advanced usage examples
For more advanced usage examples you can take a look at those two, open to public, implementations:
- thaum-xyz/ankhmorpork - extending kube-prometheus to adapt to a required environment
- openshift/cluster-monitoring-operator - using kube-prometheus components as standalone libraries to build a custom solution
Final note
Refactoring was a huge undertaking and possibly this document didn't describe in enough detail how to help you with migration to the new stack. If that is the case, please reach out to us by using GitHub discussions feature or directly on #prometheus-operator kubernetes slack channel.