A horizontal pod autoscaler, defined by a
HorizontalPodAutoscaler object, specifies how the system should automatically increase or decrease the scale of a replication controller or deployment configuration, based on metrics collected from the pods that belong to that replication controller or deployment configuration.
The following metrics are supported by horizontal pod autoscalers:
Percentage of the requested CPU
You can create a horizontal pod autoscaler with the
oc autoscale command and specify the minimum and maximum number of pods you want to run, as well as the CPU utilization your pods should target.
After a horizontal pod autoscaler is created, it begins attempting to query Heapster for metrics on the pods. It may take one to two minutes before Heapster obtains the initial metrics.
After metrics are available in Heapster, the horizontal pod autoscaler computes the ratio of the current metric utilization with the desired metric utilization, and scales up or down accordingly. The scaling will occur at a regular interval, but it may take one to two minutes before metrics make their way into Heapster.
For replication controllers, this scaling corresponds directly to the replicas of the replication controller. For deployment configurations, scaling corresponds directly to the replica count of the deployment configuration. Note that autoscaling applies only to the latest deployment in the
Creating a Horizontal Pod Autoscaler
oc autoscale command and specify at least the maximum number of pods you want to run at any given time. You can optionally specify the minimum number of pods and the average CPU utilization your pods should target, otherwise those are given default values from the AusNimbus server.
$ oc autoscale dc/frontend --min 1 --max 10 --cpu-percent=80 deploymentconfig "frontend" autoscaled
The above example creates a horizontal pod autoscaler with the following definition:
apiVersion: extensions/v1beta1 kind: HorizontalPodAutoscaler metadata: name: frontend spec: scaleRef: kind: DeploymentConfig name: frontend apiVersion: v1 subresource: scale minReplicas: 1 maxReplicas: 10 cpuUtilization: targetPercentage: 80
The name of this horizontal pod autoscaler object
The kind of object to scale
The name of the object to scale
The API version of the object to scale
The minimum number of replicas to which to scale down
The maximum number of replicas to which to scale up
The percentage of the requested CPU that each pod should ideally be using
Viewing a Horizontal Pod Autoscaler
To view the status of a horizontal pod autoscaler:
$ oc get hpa/frontend NAME REFERENCE TARGET CURRENT MINPODS MAXPODS AGE frontend DeploymentConfig/default/frontend/scale 80% 79% 1 10 8d $ oc describe hpa/frontend Name: frontend Namespace: default Labels: <none> CreationTimestamp: Mon, 26 Oct 2015 21:13:47 -0400 Reference: DeploymentConfig/default/frontend/scale Target CPU utilization: 80% Current CPU utilization: 79% Min pods: 1 Max pods: 10