<p>I have a node auto-scaling shell script which takes care of auto-scaling the worker nodes based on the average CPU/memory of all the nodes in the <code>Kubernetes</code> cluster.</p>

<p>I currently run this script from a bastion where I have the <code>pks</code>, <code>kubectl</code> cli installed and have also configured a cron-job to run it every 5 minutes.</p>

<p>Is there any other way to do this in <code>Kubernetes</code> ( <code>PKS</code> on AWS) ?</p>

<p>Or may be without using a cron-job, as the auto-scaling becomes completely dependent on the <code>cron</code>.</p>

<p>Thanks </p>

Dilip
<h1>TL;DR: Autoscale with <code>k8s</code></h1>

<p>To setup autoscaling on <code>k8s</code> use:</p>

<pre><code>kubectl autoscale -f &lt;controller&gt;.yaml --min=3 --max=5
</code></pre>

<h2>Note: PKS over AWS is an overkill</h2>

<p>You mentioned <a href="https://cloud.vmware.com/vmware-enterprise-pks" rel="nofollow noreferrer"><code>PKS</code></a></p>

<p>Using <code>PKS</code> over <code>AWS</code> infrastructure seems as overkill. Just because <code>AWS</code> has <a href="https://aws.amazon.com/eks/" rel="nofollow noreferrer"><code>EKS</code></a></p>

<p>To work with <code>AWS</code> cloud, VMware <a href="https://www.vmware.com/ru/products/cloud-foundation.html" rel="nofollow noreferrer">recommends</a> <a href="https://cloud.vmware.com/vmc-aws" rel="nofollow noreferrer">VMC on AWS</a> </p>

<h2><code>PKS</code> autoscale</h2>

<p>If you do insist to use <code>PKS</code> over <code>AWS</code>, you may try this sample repo: <a href="https://github.com/warroyo/pks-autoscale" rel="nofollow noreferrer">pks-autoscale</a></p>

<p><a href="https://github.com/warroyo/" rel="nofollow noreferrer">Author</a> of the repo also has great <a href="https://github.com/warroyo/pks-aws-quickstart" rel="nofollow noreferrer"><code>PKS</code> quickstart guide for <code>aws</code></a></p>

<h1>Scaling on <code>AWS</code></h1>

<h2><code>EKS</code> autoscaling</h2>

<p><code>AWS</code> <code>EKS</code> <a href="https://docs.aws.amazon.com/eks/latest/userguide/autoscaling.html" rel="nofollow noreferrer">supports</a> <a href="https://microservices.io/articles/scalecube.htmlg" rel="nofollow noreferrer">three-dimensional scaling</a>: </p>

<blockquote>
  <ul>
  <li><a href="https://docs.aws.amazon.com/eks/latest/userguide/cluster-autoscaler.html" rel="nofollow noreferrer">Cluster Autoscaler</a> — The Kubernetes Cluster Autoscaler automatically adjusts the number of nodes in your cluster when pods fail to launch due to lack of resources or when nodes in the cluster are underutilized and their pods can be rescheduled on to other nodes in the cluster.</li>
  <li><a href="https://docs.aws.amazon.com/eks/latest/userguide/horizontal-pod-autoscaler.html" rel="nofollow noreferrer">Horizontal Pod Autoscaler</a> — The Kubernetes Horizontal Pod Autoscaler automatically scales the number of pods in a deployment, replication controller, or replica set based on that resource's CPU utilization.</li>
  <li><a href="https://docs.aws.amazon.com/eks/latest/userguide/vertical-pod-autoscaler.html" rel="nofollow noreferrer">Vertical Pod Autoscaler</a> — The Kubernetes Vertical Pod Autoscaler automatically adjusts the CPU and memory reservations for your pods to help "right size" your applications. This can help you to better use your cluster resources and free up CPU and memory for other pods.</li>
  </ul>
</blockquote>

<h2><code>EC2</code> Auto Scaling</h2>

<p>If you decided to build your own <code>k8s</code> cluster using <code>PKS</code>, you may use <code>EC2</code> auto scaling - just <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/GettingStartedTutorial.html#gs-create-asg" rel="nofollow noreferrer">create an Auto Scaling Group</a>.</p>

<p>Using <code>aws-cli</code>:</p>

<pre><code>aws autoscaling create-auto-scaling-group --auto-scaling-group-name &lt;my-asg&gt; --launch-configuration-name &lt;my-launch-config&gt; --min-size 3 --max-size 5 --vpc-zone-identifier "&lt;zones&gt;
</code></pre>

<h2><code>EC2</code> predictive scaling</h2>

<p>Recently, AWS introduced <a href="https://aws.amazon.com/blogs/aws/new-predictive-scaling-for-ec2-powered-by-machine-learning/" rel="nofollow noreferrer">predictive scaling for EC2</a>:</p>

<blockquote>
  <p>... predictive scaling. Using data collected from your actual EC2 usage and further informed by billions of data points drawn from our own observations, we use well-trained Machine Learning models to predict your expected traffic (and EC2 usage) including daily and weekly patterns.</p>
</blockquote>
