Skip to content

docs: updated VPA CustomResourceStateMetrics docs #2193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions docs/metrics/extend/customresourcestate-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,9 @@ kube_customresource_verticalpodautoscaler_status_recommendation_containerrecomme

#### VerticalPodAutoscaler

In v2.9.0 the `vericalpodautoscalers` resource was removed from the list of default resources. In order to generate metrics for `verticalpodautoscalers`, you can use the following Custom Resource State config:
In v2.9.0 the `verticalpodautoscalers` resource was removed from the list of default resources. In order to generate Memory / CPU recommendation metrics for `verticalpodautoscalers`, you can use the following Custom Resource State config:

```yaml
# Using --resource=verticalpodautoscalers, we get the following output:
# HELP kube_verticalpodautoscaler_annotations Kubernetes annotations converted to Prometheus labels.
# TYPE kube_verticalpodautoscaler_annotations gauge
# kube_verticalpodautoscaler_annotations{namespace="default",verticalpodautoscaler="hamster-vpa",target_api_version="apps/v1",target_kind="Deployment",target_name="hamster"} 1
# A similar result can be achieved by specifying the following in --custom-resource-state-config:
kind: CustomResourceStateMetrics
spec:
resources:
Expand All @@ -347,19 +342,49 @@ spec:
target_kind: [spec, targetRef, kind]
target_name: [spec, targetRef, name]
metrics:
- name: "annotations"
help: "Kubernetes annotations converted to Prometheus labels."
- name: "vpa_containerrecommendations_target_memory"
help: "VPA container recommendations for memory (in bytes)."
each:
type: Gauge
gauge:
path: [metadata, annotations]
# This will output the following metric:
# HELP kube_customresource_autoscaling_annotations Kubernetes annotations converted to Prometheus labels.
# TYPE kube_customresource_autoscaling_annotations gauge
# kube_customresource_autoscaling_annotations{customresource_group="autoscaling.k8s.io", customresource_kind="VerticalPodAutoscaler", customresource_version="v1", namespace="default",target_api_version="autoscaling.k8s.io/v1",target_kind="Deployment",target_name="hamster",verticalpodautoscaler="hamster-vpa"} 123
path: [status, recommendation, containerRecommendations]
valueFrom: [target, memory]
labelsFromPath:
container: [containerName]
- name: "vpa_containerrecommendations_target_cpu"
help: "VPA container recommendations for cpu (in cores)."
each:
type: Gauge
gauge:
path: [status, recommendation, containerRecommendations]
valueFrom: [target, cpu]
labelsFromPath:
container: [containerName]
```

The above configuration was tested on [this](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/examples/hamster.yaml) VPA configuration, outputting the following metrics:

```
# HELP kube_customresource_vpa_containerrecommendations_target_memory VPA container recommendations for memory (in bytes).
kube_customresource_vpa_containerrecommendations_target_memory{container="hamster",customresource_group="autoscaling.k8s.io",customresource_kind="VerticalPodAutoscaler",customresource_version="v1",namespace="default",target_api_version="autoscaling.k8s.io/v1",target_kind="Deployment",target_name="hamster",verticalpodautoscaler="hamster-vpa"} 1.048576e+08

# HELP kube_customresource_vpa_containerrecommendations_target_cpu VPA container recommendations for cpu (in cores).
kube_customresource_vpa_containerrecommendations_target_cpu{container="hamster",customresource_group="autoscaling.k8s.io",customresource_kind="VerticalPodAutoscaler",customresource_version="v1",namespace="default",target_api_version="autoscaling.k8s.io/v1",target_kind="Deployment",target_name="hamster",verticalpodautoscaler="hamster-vpa"} 0.1
```

The above configuration was tested on [this](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/examples/hamster.yaml) VPA configuration, with an added annotation (`foo: 123`).
In RBAC-enabled clusters and to ensure that the VPA Metrics will be captured seamlessly, make sure that the Cluster Role / Role assigned to the Kube State Metrics has permissions to `list` & `watch` VPA resources (as well as `customresourcedefinitions`) e.g.:

```yaml
- verbs:
- list
- watch
apiGroups:
- autoscaling.k8s.io
- apiextensions.k8s.io
resources:
- verticalpodautoscalers
- customresourcedefinitions
```

#### All VerticalPodAutoscaler Metrics

Expand Down