Autoscaling
Module
The Horizontal Pod Autoscaler automatically scales the number of pods in a replication controller, deployment or replica set based on observed CPU utilization.
Overview
At the end of this module, you will :
Learn the format of a YAML Autoscale file
Learn how to manage a Autoscale
Learn the composition of a Autoscale
Prerequisites
Create the directory data/autoscaling
in your home folder to manage the YAML file needed in this module.
This module needs the metrics-server to be deployed on the cluster to get the monitoring values like CPU and memory. Ensure that the module is up and running before continuing.
Create
Looks up a Deployment, ReplicaSet, or ReplicationController by name and creates an autoscaler that uses the given resource as a reference. An autoscaler can automatically increase or decrease number of pods deployed within the system as needed.
Horizontal Pod Autoscaler automatically scales the number of pods in a deployment or replica set based on observed CPU, Memory or Custom Metrics utilization depending the API version used.
The Kubernetes basic autoscaling architecture can be schematized like this :
The create command can directly ask the API resource to create an HorizontalPodAutoscaler in command line or create an HorizontalPodAutoscaler object based on a yaml file definition.
Exercise n°1
Run a sample app based on a webserver to expose it on port 80.
Create an Horizontal Pod Autoscaler to automatically scale the Deployment if the CPU usage is above 50%.
Exercise n°2
Run a sample nginx application exposing port 8080
Create an Horizontal Pod Autoscaler to automatically scale the Deployment if the memory is above 50%.
Get
The get command list the object asked. It could be a single object or a list of multiple objects comma separated. This command is useful to get the status of each object. The output can be formatted to only display some information based on some json search or external tools like tr
, sort
, uniq
.
The default output display some useful information about each services :
Name : the name for the newly created object
Reference : the object managed by the autoscaler, like Pod name, a Deployment name ...
Targets : the metrics defined to autoscale the referenced resource
Minpods : the lower limit for the number of pods that can be set by the autoscaler
Maxpods : the upper limit for the number of pods that can be set by the autoscaler
Replicas : the current replicas number
Age : the age of the object from his creation
Exercise n°1
Get the current HorizontalPodAutoscaler resources in the default namespace.
Exercise n°2
Stress the Pod created in the previous section and check the HorizontalPoMindAutoscaler associated.
Scale the load-generator if you want to stress the php-apache Pods quickly.
Longer Execution Times
The autoscaling can take more than 2 minutes to run. Please be patient. Do not close the window or cancel the operation.
Exercise n°3
Stop to stress the Pod previously created and check that the autoscaler come back to normal.
Describe
Once an object is running, it is inevitably a need to debug problems or check the configuration deployed.
The describe command display a lot of configuration information about the Horizontal Pod Autoscaler (labels, annotations, etc.) and the scale policy (selector, type, number of pods, ...).
This command is really useful to introspect and debug an object deployed in a cluster.
Exercise n°1
Describe one of the existing Autoscaler in the default namespace.
Explain
Kubernetes come with a lot of documentation about his objects and the available options in each one. Those information can be fin easily in command line or in the official Kubernetes documentation.
The explain command allows to directly ask the API resource via the command line tools to display information about each Kubernetes objects and their architecture.
Exercise n°1
Get the documentation of a specific field of a resource.
Add the --recursive flag to display all of the fields at once without descriptions.
Delete
The delete command delete resources by filenames, stdin, resources and names, or by resources and label selector.
Be careful on the deletion of an autoscaling object, this can have effects in the availability of the services associated.
Note that the delete command does NOT do resource version checks, so if someone submits an update to a resource right when you submit a delete, their update will be lost along with the rest of the resource.
Exercise n°1
Delete the previous autoscaling group created in command line.
Module exercise
The purpose of this section is to manage each steps of the lifecycle of an application to better understand each concepts of the Kubernetes course.
The main objective in this module is to understand how to dynamically and automatically manage the number of Pods needed to handle the workload.
For more information about the application used all along the course, please refer to the Exercise App > Voting App link in the left panel.
Based on the principles explain in this module, try by your own to handle this steps. The development of a yaml file is recommended.
The file developed has to be stored in this directory : ~/data/votingapp/10_autoscaling
Manage the HorizontalPodAutoscaler of the worker Pods to :
Ensure that the worker has minimum one Pods
Ensure that the worker has maximum five Pods
Ensure that the Pods is autoscaled when the CPU is above 80%.
External documentation
Those documentations can help you to go further in this topic :
Kubernetes official documentation on Horizontal Pod Auto Scaling (HPA)
Kubernetes official documentation walkthrough HPA
Kubernetes official documentation of autoscale API
Last updated