Annotating Machine Deployment for Autoscaling

KKP
October 14, 2021

Machine Deployment Annotation for Autoscaling

In the last post, we discussed Kubernetes Autoscaler in KKP as well as its usage. We also showed you how to install Kubernetes Autoscaler on a KKP Cluster. Now let’s take it a step further and show you how to annotate the MachineDeployments which you want the Autoscaler to recognize.

How to Annotate Machine Deployments for Autoscaling?

The Cluster Autoscaler only recognizes MachineDeployments with valid annotations. The annotations are used to control the minimum and maximum number of replicas per MachineDeployment. These annotations can also be applied to just MachineDeployments that Cluster Autoscaler should consider, rather than all MachineDeployment objects. See annotation command below:

cluster.k8s.io/cluster-api-autoscaler-node-group-min-size - the minimum number of replicas (must be greater than zero)

cluster.k8s.io/cluster-api-autoscaler-node-group-max-size - the maximum number of replicas

You can apply the annotations to MachineDeployments once they are created and running by following these steps:

Step 1: It is assumed that you already have a running KKP Cluster and the MachineDeployments have been created and running.

Step 2: Run the following kubectl command to check the available MachineDeployments on the Cluster:

$ kubectl get machinedeployments -n kube-system


NAME                  AGE   DELETED   REPLICAS   AVAILABLEREPLICAS   PROVIDER     OS     VERSION
test-worker-6wjcx    3h56m               2                2            aws      ubuntu    1.19.9
test-worker-pndqd    3h59m               1                1            aws      ubuntu    1.19.9

Step 3: The annotation command will be used with one of the MachineDeployments above to annotate the desired MachineDeployments. In this case, the test-worker-6wjcx will be annotated, and the minimum and maximum will be set.

Minimum annotation:

kubectl annotate machinedeployment -n kube-system test-worker-6wjcx cluster.k8s.io/cluster-api-autoscaler-node-group-min-size="1"

machinedeployment.cluster.k8s.io/test-worker-6wjcx annotated

Maximum annotation:

kubectl annotate machinedeployment -n kube-system test-worker-6wjcx cluster.k8s.io/cluster-api-autoscaler-node-group-max-size="5"

machinedeployment.cluster.k8s.io/test-worker-6wjcx annotated

Step 4: Check the MachineDeployment description.

$ kubectl describe machinedeployments -n kube-system test-worker-6wjcx

Name:         test-worker-6wjcx
Namespace:    kube-system
Labels:       <none>
Annotations:  cluster.k8s.io/cluster-api-autoscaler-node-group-max-size: 5
           cluster.k8s.io/cluster-api-autoscaler-node-group-min-size: 1
           machinedeployment.clusters.k8s.io/revision: 1
API Version:  cluster.k8s.io/v1alpha1
Kind:         MachineDeployment
Metadata:
  Creation Timestamp:  2021-07-23T11:05:11Z
  Finalizers:
    foregroundDeletion
  Generate Name:  test-worker-
  Generation:     1
  Managed Fields:
    API Version:  cluster.k8s.io/v1alpha1
    Fields Type:  FieldsV1
    fieldsV1:
      F:metadata:
……………………
The description details show that the MachineDeployment 
has been annotated with a minimum of 1 and a maximum of 5. 
The Autoscaler will only consider the annotated 
MachineDeployment on the Cluster.  

Step 5: Edit Autoscaler 

To edit Autoscaler, click on the three dots in front of the Cluster Autoscaler in the Addons section of the Cluster dashboard and select edit.

Edit autoscaler image

Step 6: Delete Autoscaler

You can delete Autoscaler by selecting delete from the drop-down menu, as shown below.

Delete autoscaler image

Once the delete is confirmed, you can check the Cluster to ensure that the Autoscaler has been deleted using kubectl get pods -n kube-system command.

The output should be the same as the first.

Summary: Congratulations! You have successfully annotated your desired Machine Deployment, in order to deploy Autoscaler to optimize your resources, which will likely result in significant cost savings! Please check the “learn more” section below for more resources on Kubernetes Autoscaler and how to annotate MachineDeployment for Autoscaling.

Learn More

Seyi Ewegbemi

Seyi Ewegbemi

Student Worker