Skip to content

Latest commit

 

History

History
84 lines (72 loc) · 2.94 KB

nodes-pods-autoscaling-creating-cpu.adoc

File metadata and controls

84 lines (72 loc) · 2.94 KB

Creating a horizontal pod autoscaler for CPU utilization

You can create a horizontal pod autoscaler (HPA) to automatically scale pods when CPU usage exceeds a specified percentage. You create the HPA for a replication controller or deployment controller, based on how your pods were created.

Prerequisites

In order to use horizontal pod autoscalers, your cluster administrator must have properly configured cluster metrics. You can use the oc describe PodMetrics <pod-name> command to determine if metrics are configured. If metrics are configured, the output appears similar to the following, with Cpu and Memory displayed under Usage.

$ oc describe PodMetrics openshift-kube-scheduler-ip-10-0-135-131.ec2.internal
Name:         openshift-kube-scheduler-ip-10-0-135-131.ec2.internal
Namespace:    openshift-kube-scheduler
Labels:       <none>
Annotations:  <none>
API Version:  metrics.k8s.io/v1beta1
Containers:
  Name:  wait-for-host-port
  Usage:
    Memory:  0
  Name:      scheduler
  Usage:
    Cpu:     8m
    Memory:  45440Ki
Kind:        PodMetrics
Metadata:
  Creation Timestamp:  2019-05-23T18:47:56Z
  Self Link:           /apis/metrics.k8s.io/v1beta1/namespaces/openshift-kube-scheduler/pods/openshift-kube-scheduler-ip-10-0-135-131.ec2.internal
Timestamp:             2019-05-23T18:47:56Z
Window:                1m0s
Events:                <none>
Procedure
  • Use one of the following commands to create a horizontal pod autoscaler for CPU utilization for a deployment controller or a replication controller:

    oc autoscale dc/<deployment-name> \//(1)
      --min <number> \//(2)
      --max <number> \//(3)
      --cpu-percent=<percent> (4)
    
    oc autoscale rc/<file-name> --min <number> --max <number> --cpu-percent=<percent>
    1. Specify the deployment object or replica file.

    2. Specify the minimum number of replicas when scaling down.

    3. Specify the maximum number of replicas when scaling up.

    4. Specify the target average CPU utilization, represented as a percent of requested CPU, over all the pods. If not specified or negative, a default autoscaling policy will be used.

      For example:

      oc autoscale dc/example --min=5 --max=7 --cpu-percent=75

      The following example shows autoscaling for the example deployment configuration. The initial deployment requires 3 pods. The HPA object increased that minumum to 5 and will increase the pods up to 7 if CPU usage on the pods reaches 75%:

      $ oc get dc example
      NAME      REVISION   DESIRED   CURRENT   TRIGGERED BY
      example   1          3         3         config
      
      $ oc autoscale dc/example --min=5 --max=7 --cpu-percent=75
      horizontalpodautoscaler.autoscaling/example autoscaled
      
      $ oc get dc
      NAME      REVISION   DESIRED   CURRENT   TRIGGERED BY
      example   1          5         5         config