content_image/819361.jpg
An HPA for the random-generator  Deployment can be created with the command in Example 24-3. For the HPA to have any effect, it is important that the Deployment declare a .spec.resources.requests  limit for the CPU as described in Chapter 2, Predictable Demands . Another requirement is that you have the metrics server enabled, which is a cluster-wide aggregator of resource usage data. 

kubectl autoscale deployment random-generator --cpu-percent=50 --min=1 --max=5 

The preceding command will create the HPA definition shown in Example 24-4. 

apiVersion : autoscaling/v2beta2 kind : HorizontalPodAutoscaler metadata : name : random-generator spec : minReplicas : 1 maxReplicas : 5 scaleTargetRef : apiVersion : extensions/v1beta1 kind : Deployment name : random-generator metrics : - resource : name : cpu target : averageUtilization : 50 type : Utilization type : Resource 

Minimum number of Pods that should always run 

<img src='content_image/819361.jpg'>

Maximum number of Pods until the HPA can scale up 

Reference to the object that should be associated with this HPA 

Desired CPU usage as a percentage of the Pods, requested CPU resource. For example, when the Pods have a .spec.resources.requests.cpu  of 200m, a scale-up happens when on average more than 100m CPU (= 50%) is utilized. 

