Application autoscaling
A recent feature addition to Kubernetes is that of the Horizontal Pod Autoscaler. This resource type is really useful as it gives us a way to automatically set thresholds for scaling our application. Currently, that support is only for CPU, but there is alpha support for custom application metrics as well.
Let's use the node-js-scale
ReplicationController
from the beginning of the chapter and add an autoscaling component. Before we start, let's make sure we are scaled back down to one replica using the following command:
$ kubectl scale --replicas=1 rc/node-js-scale
Now, we can create a Horizontal Pod Autoscaler, node-js-scale-hpa.yaml
with the following hpa
definition:
apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: name: node-js-scale spec: minReplicas: 1 maxReplicas: 3 scaleTargetRef: apiVersion: v1 kind: ReplicationController name: node-js-scale targetCPUUtilizationPercentage: 20
Go ahead and create this with thekubectl create...