Setting up a vanilla prometheus-metrics-adapter is a time-consuming process. Happily, we have somewhat simplified it by defining a set of CustomResourceDefinitions with different scopes.
You can globally define a metric using the cluster-wide resource, while the namespaced resource allows you to redefine it locally. All custom resources have the same format.
Namespaced custom resources
ServiceMetric
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",service="myservice"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,servicelabels for grouping (max() by(...),sum() by (...), etc.).
IngressMetric
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",ingress="myingress"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,ingresslabels for grouping (max() by(...),sum() by (...), etc.).
PodMetric
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",pod="mypod-xxxxx"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,podlabels for grouping (max() by(...),sum() by (...), etc.).
DeploymentMetric
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",deployment="mydeployment"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,deploymentlabels for grouping (max() by(...),sum() by (...), etc.).
StatefulSetMetric
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",statefulset="mystatefulset"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,statefulsetlabels for grouping (max() by(...),sum() by (...), etc.).
NamespaceMetric
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespacelabels for grouping (max() by(...),sum() by (...), etc.).
DaemonSetMetric (not available to users)
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",daemonset="mydaemonset"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,daemonsetlabels for grouping (max() by(...),sum() by (...), etc.).
Cluster custom resources
ClusterServiceMetric (not available to users)
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",service="myservice"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,servicelabels for grouping (max() by(...),sum() by (...), etc.).
ClusterIngressMetric (not available to users)
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",ingress="myingress"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,ingresslabels for grouping (max() by(...),sum() by (...), etc.).
ClusterPodMetric (not available to users)
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",pod="mypod-xxxxx"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,podlabels for grouping (max() by(...),sum() by (...), etc.).
ClusterDeploymentMetric (not available to users)
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",deployment="mydeployment"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,deploymentlabels for grouping (max() by(...),sum() by (...), etc.).
ClusterStatefulSetMetric (not available to users)
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",statefulset="mystatefulset"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,statefulsetlabels for grouping (max() by(...),sum() by (...), etc.).
ClusterDaemonSetMetric (not available to users)
.metadata.name— the name of the metric (used in HPA)..spec.query— a custom PromQL query that returns a unique value for your label set (you can usesum() by(),max() by(), etc., operators for grouping). The following keys must be used in the request:<<.LabelMatchers>>— will be replaced with a set of{namespace="mynamespace",daemonset="mydaemonset"}labels. You can add your own comma-separated labels list (as in the example).<<.GroupBy>>— will be replaced withnamespace,daemonsetlabels for grouping (max() by(...),sum() by (...), etc.).