Class HorizontalPodAutoscaler
- java.lang.Object
-
- software.amazon.jsii.JsiiObject
-
- software.constructs.Construct
-
- org.cdk8s.plus24.Resource
-
- org.cdk8s.plus24.HorizontalPodAutoscaler
-
- All Implemented Interfaces:
IApiEndpoint
,IApiResource
,IResource
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
,software.constructs.IDependable
@Generated(value="jsii-pacmak/1.74.0 (build 6d08790)", date="2023-02-04T02:31:04.858Z") @Stability(Stable) public class HorizontalPodAutoscaler extends Resource
A HorizontalPodAutoscaler scales a workload up or down in response to a metric change.This allows your services to scale up when demand is high and scale down when they are no longer needed.
Typical use cases for HorizontalPodAutoscaler:
- When Memory usage is above 70%, scale up the number of replicas to meet the demand.
- When CPU usage is below 30%, scale down the number of replicas to save resources.
- When a service is experiencing a spike in traffic, scale up the number of replicas to meet the demand. Then, when the traffic subsides, scale down the number of replicas to save resources.
The autoscaler uses the following algorithm to determine the number of replicas to scale:
desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]
HorizontalPodAutoscaler's can be used to with any
Scalable
workload:- Deployment
- StatefulSet
Targets that already have a replica count defined:
Remove any replica counts from the target resource before associating with a HorizontalPodAutoscaler. If this isn't done, then any time a change to that object is applied, Kubernetes will scale the current number of Pods to the value of the target.replicas key. This may not be desired and could lead to unexpected behavior.
Example:
const backend = new kplus.Deployment(this, 'Backend', ...); const hpa = new kplus.HorizontalPodAutoscaler(chart, 'Hpa', { target: backend, maxReplicas: 10, scaleUp: { policies: [ { replicas: kplus.Replicas.absolute(3), duration: Duration.minutes(5), }, ], }, });
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HorizontalPodAutoscaler.Builder
A fluent builder forHorizontalPodAutoscaler
.-
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
-
Nested classes/interfaces inherited from interface org.cdk8s.plus24.IApiEndpoint
IApiEndpoint.Jsii$Default
-
Nested classes/interfaces inherited from interface org.cdk8s.plus24.IApiResource
IApiResource.Jsii$Default
-
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
-
Nested classes/interfaces inherited from interface org.cdk8s.plus24.IResource
IResource.Jsii$Default
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HorizontalPodAutoscaler(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
protected
HorizontalPodAutoscaler(software.amazon.jsii.JsiiObjectRef objRef)
HorizontalPodAutoscaler(software.constructs.Construct scope, String id, HorizontalPodAutoscalerProps props)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.cdk8s.ApiObject
getApiObject()
The underlying cdk8s API object.Number
getMaxReplicas()
The maximum number of replicas that can be scaled up to.List<Metric>
getMetrics()
The metric conditions that trigger a scale up or scale down.Number
getMinReplicas()
The minimum number of replicas that can be scaled down to.String
getResourceType()
The name of a resource type as it appears in the relevant API endpoint.ScalingRules
getScaleDown()
The scaling behavior when scaling down.ScalingRules
getScaleUp()
The scaling behavior when scaling up.IScalable
getTarget()
The workload to scale up or down.-
Methods inherited from class org.cdk8s.plus24.Resource
asApiResource, asNonApiResource, getApiGroup, getApiVersion, getKind, getMetadata, getName, getPermissions, getResourceName
-
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
-
-
-
-
Constructor Detail
-
HorizontalPodAutoscaler
protected HorizontalPodAutoscaler(software.amazon.jsii.JsiiObjectRef objRef)
-
HorizontalPodAutoscaler
protected HorizontalPodAutoscaler(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
-
HorizontalPodAutoscaler
@Stability(Stable) public HorizontalPodAutoscaler(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull HorizontalPodAutoscalerProps props)
- Parameters:
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.
-
-
Method Detail
-
getApiObject
@Stability(Stable) @NotNull protected org.cdk8s.ApiObject getApiObject()
The underlying cdk8s API object.- Specified by:
getApiObject
in classResource
- See Also:
- base.Resource.apiObject
-
getMaxReplicas
@Stability(Stable) @NotNull public Number getMaxReplicas()
The maximum number of replicas that can be scaled up to.
-
getMinReplicas
@Stability(Stable) @NotNull public Number getMinReplicas()
The minimum number of replicas that can be scaled down to.
-
getResourceType
@Stability(Stable) @NotNull public String getResourceType()
The name of a resource type as it appears in the relevant API endpoint.- Specified by:
getResourceType
in interfaceIApiResource
- Specified by:
getResourceType
in classResource
- See Also:
- https://kubernetes.io/docs/reference/access-authn-authz/rbac/#referring-to-resources
-
getScaleDown
@Stability(Stable) @NotNull public ScalingRules getScaleDown()
The scaling behavior when scaling down.
-
getScaleUp
@Stability(Stable) @NotNull public ScalingRules getScaleUp()
The scaling behavior when scaling up.
-
getTarget
@Stability(Stable) @NotNull public IScalable getTarget()
The workload to scale up or down.
-
-