Sign Up for the Quarterly Newsletter

vSphere Pod Autoscaler

This Fling is useful for vSphere PodVM users who want to perform auto-scaling on vSphere PodVMs based on memory utilization.

This python script is intended to implement the Horizontal Pod Autoscaler algorithm for podVM for the vSphere 7.0 with Kubernetes. The implementation follows the algorithm from the official Kubernetes documents: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/

This script will automatically scale the number of PodVMs in the environment. The script will perform the following actions:

  1. The script will retrieve the memory utilization of PodVMs in the environment
  2. The script will then allow users to provide the memory threshold for PodVMs
  3. The script will then calculate the desired number of replicas based on the memory threshold and utilization
  4. The script will automatically scale the PodVMs to the desired number of replicas calculated in step #3

VMware 

  • vSphere 7.0 with Kubernetes
  • vCenter Server 7.0

Other 

We have provided a zipped folder with the script. Please unzip the folder to retrieve the script.

 To run this script as a standalone:

  1. git clone this repo

  2. pip install pyvmomi

  3. Do a 'kubectl vsphere login' to login into your Supervisor Cluster for vSphere 7.0 with Kubernetes
    vSphere with Kubernetes Guide: Page 84

  4. Choose the context which you want by doing 'kubectl config use-context <YOUR_NAMEPSACE>'
    vSphere with Kubernetes Guide: Page 84
  5. Export these values
    # export VC_PASSWRD=XXXX
    # export VC_USERNAME=administrator@vsphere.local
    # export VC_HOST=jur01-vcenter01.acepod.com
    # export VC_PORT=443


  6. python3 hpa_autoscaler.py -mem_threshold_percent
    <MEMORY_THRESHOLD> -secure <YES_OR_NO>

Notes

  • Example 1: if you want to connect securely to the vSphere hosts:
python3 hpa_autoscaler.py  -mem_threshold_percent 20 -secure yes

 

  • Example 2: if you want to connect insecurely to the vSphere hosts:
python3 hpa_autoscaler.py  -mem_threshold_percent 20 -secure no