1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/nodes-pods-vertical-autoscaler-custom-resource.adoc

94 lines
3.2 KiB
Plaintext

// Module included in the following assemblies:
//
// * nodes/nodes-vertical-autoscaler.adoc
:_mod-docs-content-type: REFERENCE
[id="nodes-pods-vertical-autoscaler-custom-resource_{context}"]
= Example custom resources for the Vertical Pod Autoscaler
The Vertical Pod Autoscaler Operator (VPA) can update not only built-in resources such as deployments or stateful sets, but also custom resources that manage pods.
To use the VPA with a custom resource when you create the `CustomResourceDefinition` (CRD) object, you must configure the `labelSelectorPath` field in the `/scale` subresource. The `/scale` subresource creates a `Scale` object. The `labelSelectorPath` field defines the JSON path inside the custom resource that corresponds to `status.selector` in the `Scale` object and in the custom resource. The following is an example of a `CustomResourceDefinition` and a `CustomResource` that fulfills these requirements, along with a `VerticalPodAutoscaler` definition that targets the custom resource. The following example shows the `/scale` subresource contract.
[NOTE]
====
This example does not result in the VPA scaling pods because there is no controller for the custom resource that allows it to own any pods. As such, you must write a controller in a language supported by Kubernetes to manage the reconciliation and state management between the custom resource and your pods. The example illustrates the configuration for the VPA to understand the custom resource as scalable.
====
.Example custom CRD, CR
[source,yaml]
----
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: scalablepods.testing.openshift.io
spec:
group: testing.openshift.io
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
replicas:
type: integer
minimum: 0
selector:
type: string
status:
type: object
properties:
replicas:
type: integer
subresources:
status: {}
scale:
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
labelSelectorPath: .spec.selector <1>
scope: Namespaced
names:
plural: scalablepods
singular: scalablepod
kind: ScalablePod
shortNames:
- spod
----
<1> Specifies the JSON path that corresponds to `status.selector` field of the custom resource object.
.Example custom CR
[source,yaml]
----
apiVersion: testing.openshift.io/v1
kind: ScalablePod
metadata:
name: scalable-cr
namespace: default
spec:
selector: "app=scalable-cr" <1>
replicas: 1
----
<1> Specify the label type to apply to managed pods. This is the field that the `labelSelectorPath` references in the custom resource definition object.
.Example VPA object
[source,yaml]
----
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: scalable-cr
namespace: default
spec:
targetRef:
apiVersion: testing.openshift.io/v1
kind: ScalablePod
name: scalable-cr
updatePolicy:
updateMode: "InPlaceOrRecreate"
----