mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
145 lines
4.8 KiB
Plaintext
145 lines
4.8 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * nodes/nodes-pods-autoscaling.adoc
|
|
|
|
:_mod-docs-content-type: PROCEDURE
|
|
[id="nodes-pods-autoscaling-creating-memory-specific_{context}"]
|
|
|
|
= Creating a horizontal pod autoscaler object for specific memory use
|
|
|
|
Using the {product-title} CLI, you can create a horizontal pod autoscaler (HPA) to automatically scale an existing object. The HPA scales the pods associated with that object to maintain the average memory use that you specify.
|
|
|
|
[NOTE]
|
|
====
|
|
Use a `Deployment` object or `ReplicaSet` object unless you need a specific feature or behavior provided by other objects.
|
|
====
|
|
|
|
You can specify the minimum and maximum number of pods and the average memory use that your pods should target. If you do not specify a minimum, the pods are given default values from the {product-title} server.
|
|
|
|
.Prerequisites
|
|
|
|
include::snippets/nodes-pods-autoscaling-creating-cpu-prereqs.adoc[]
|
|
|
|
.Procedure
|
|
|
|
. Create a `HorizontalPodAutoscaler` object similar to the following for an existing object:
|
|
+
|
|
[source,yaml,options="nowrap"]
|
|
----
|
|
apiVersion: autoscaling/v2 <1>
|
|
kind: HorizontalPodAutoscaler
|
|
metadata:
|
|
name: hpa-resource-metrics-memory <2>
|
|
namespace: default
|
|
spec:
|
|
scaleTargetRef:
|
|
apiVersion: apps/v1 <3>
|
|
kind: Deployment <4>
|
|
name: example <5>
|
|
minReplicas: 1 <6>
|
|
maxReplicas: 10 <7>
|
|
metrics: <8>
|
|
- type: Resource
|
|
resource:
|
|
name: memory <9>
|
|
target:
|
|
type: AverageValue <10>
|
|
averageValue: 500Mi <11>
|
|
behavior: <12>
|
|
scaleDown:
|
|
stabilizationWindowSeconds: 300
|
|
policies:
|
|
- type: Pods
|
|
value: 4
|
|
periodSeconds: 60
|
|
- type: Percent
|
|
value: 10
|
|
periodSeconds: 60
|
|
selectPolicy: Max
|
|
----
|
|
<1> Use the `autoscaling/v2` API.
|
|
<2> Specify a name for this horizontal pod autoscaler object.
|
|
<3> Specify the API version of the object to scale:
|
|
* For a `Deployment`, `ReplicaSet`, or `Statefulset` object, use `apps/v1`.
|
|
* For a `ReplicationController`, use `v1`.
|
|
* For a `DeploymentConfig`, use `apps.openshift.io/v1`.
|
|
<4> Specify the type of object. The object must be a `Deployment`, `DeploymentConfig`,
|
|
`ReplicaSet`, `ReplicationController`, or `StatefulSet`.
|
|
<5> Specify the name of the object to scale. The object must exist.
|
|
<6> Specify the minimum number of replicas when scaling down.
|
|
<7> Specify the maximum number of replicas when scaling up.
|
|
<8> Use the `metrics` parameter for memory usage.
|
|
<9> Specify `memory` for memory usage.
|
|
<10> Set the type to `AverageValue`.
|
|
<11> Specify `averageValue` and a specific memory value.
|
|
<12> Optional: Specify a scaling policy to control the rate of scaling up or down.
|
|
|
|
. Create the horizontal pod autoscaler by using a command similar to the following:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f <file-name>.yaml
|
|
----
|
|
+
|
|
For example:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f hpa.yaml
|
|
----
|
|
+
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
horizontalpodautoscaler.autoscaling/hpa-resource-metrics-memory created
|
|
----
|
|
|
|
.Verification
|
|
|
|
* Check that the horizontal pod autoscaler was created by using a command similar to the following:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc get hpa hpa-resource-metrics-memory
|
|
----
|
|
+
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
|
|
hpa-resource-metrics-memory Deployment/example 2441216/500Mi 1 10 1 20m
|
|
----
|
|
|
|
* Check the details of the horizontal pod autoscaler by using a command similar to the following:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc describe hpa hpa-resource-metrics-memory
|
|
----
|
|
+
|
|
.Example output
|
|
[source,text]
|
|
----
|
|
Name: hpa-resource-metrics-memory
|
|
Namespace: default
|
|
Labels: <none>
|
|
Annotations: <none>
|
|
CreationTimestamp: Wed, 04 Mar 2020 16:31:37 +0530
|
|
Reference: Deployment/example
|
|
Metrics: ( current / target )
|
|
resource memory on pods: 2441216 / 500Mi
|
|
Min replicas: 1
|
|
Max replicas: 10
|
|
ReplicationController pods: 1 current / 1 desired
|
|
Conditions:
|
|
Type Status Reason Message
|
|
---- ------ ------ -------
|
|
AbleToScale True ReadyForNewScale recommended size matches current size
|
|
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from memory resource
|
|
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
|
|
Events:
|
|
Type Reason Age From Message
|
|
---- ------ ---- ---- -------
|
|
Normal SuccessfulRescale 6m34s horizontal-pod-autoscaler New size: 1; reason: All metrics below target
|
|
----
|