Skip to content

Latest commit

 

History

History
103 lines (90 loc) · 4.15 KB

nodes-pods-autoscaling-creating.adoc

File metadata and controls

103 lines (90 loc) · 4.15 KB

Understanding how to create a horizontal pod autoscaler

How you create the horizontal pod autoscaler (HPA) depends on whether you want to scale for CPU or memory utilization.

CPU utilization

For CPU utilization:, you can create a horizontal pod autoscaler using the command line or by creating a HorizontalPodAutoscaler object.

When creating an HPA to control pod scaling based on CPU utilization, you specify the maximum number of pods you want to run at any given time. You can also specify a minimum number of pods.

The following command creates a Horizontal Pod Autoscaler that maintains between 1 and 10 replicas of the Pods controlled by the image-registry DeploymentConfig to maintain an average CPU utilization of 50% across all Pods.

$ oc autoscale dc/image-registry --min 1 --max 10 --cpu-percent=50

The command creates the following object configuration:

Horizontal Pod Autoscaler Object Definition for CPU utilization
$ oc edit hpa image-registry
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  annotations:
    autoscaling.alpha.kubernetes.io/conditions: '[{"type":"AbleToScale","status":"True","lastTransitionTime":"2019-05-22T20:49:57Z","reason":"SucceededGetScale","message":"the
      HPA controller was able to get the target''s current scale"},{"type":"ScalingActive","status":"False","lastTransitionTime":"2019-05-22T20:49:57Z","reason":"FailedGetResourceMetric","message":"the
      HPA was unable to compute the replica count: missing request for cpu"}]'
  creationTimestamp: 2019-05-22T20:49:42Z
  name: image-registry (1)
  namespace: default
  resourceVersion: "325215"
  selfLink: /apis/autoscaling/v1/namespaces/default/horizontalpodautoscalers/image-registry
  uid: 1fd7585a-7cd3-11e9-9d00-0e2a93384702
spec:
  maxReplicas: 10 (2)
  minReplicas: 1 (3)
  scaleTargetRef:
    apiVersion: apps.openshift.io/v1
    kind: DeploymentConfig (4)
    name: image-registry  (5)
  targetCPUUtilizationPercentage: 50 (6)
status:
  currentReplicas: 3
  desiredReplicas: 0
  1. The name of this horizontal pod autoscaler object.

  2. The lower limit for the number of pods that can be set by the autoscaler. If not specified or negative, the server will apply a default value.

  3. The upper limit for the number of pods that can be set by the autoscaler. This value is required.

  4. The kind of object to scale, DeploymentConfig or ReplicationController.

  5. The name of the object to scale.

  6. The percentage of the requested CPU that each pod should ideally be using.

    Memory utilization

    For memory utilization, you can specify the minimum number of pods and the average memory utilization your pods should target as well, otherwise those are given default values from the {product-title} server.

You can specify resource metrics in terms of direct values, instead of as percentages of the requested value, by using a target type of AverageValue instead of AverageUtilization, and setting the corresponding target.averageValue field instead of the target.averageUtilization.

Horizontal Pod Autoscaler Object Definition for memory utilization
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: memory-autoscale (1)
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1 (2)
    name: example (3)
    kind: DeploymentConfig (4)
  minReplicas: 1 (5)
  maxReplicas: 10 (6)
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization (7)
        averageUtilization: 50
  1. The name of this horizontal pod autoscaler object.

  2. The API version of the object to scale.

  3. The name of the object to scale.

  4. The kind of object to scale.

  5. The lower limit for the number of pods that can be set by the autoscaler. If not specified or negative, the server will apply a default value.

  6. The upper limit for the number of pods that can be set by the autoscaler. This value is required.

  7. The type of must be either Utilization, Value, or AverageValue.