Kf supports two primary autoscaling modes:
- Built-in autosacling similar to Cloud Foundry.
- Advanced autoscaling through the Kubernetes Horizontal Pod Autoscaler (HPA).
Kf Apps can be automatically scaled based on CPU usage. You can configure autoscaling limits for your Apps and the target CPU usage for each App instance. Kf automatically scales your Apps up and down in response to demand.
By default, autoscaling is disabled. Follow the steps below to enable autoscaling.
You can view the autoscaling status for an App using the
command. If autoscaling is enabled for an App,
Instances includes the
$ kf apps Name Instances Memory Disk CPU app1 4 (autoscaled 4 to 5) 256Mi 1Gi 100m app2 1 256Mi 1Gi 100m
Autoscaling is enabled for
min-instances set to 4 and
max-instances set to 5. Autoscaling is disabled for
Update autoscaling limits
You can update the instance limits using the
kf update-autoscaling-limits app-name min-instances max-instances
Create autoscaling rule
You can create autoscaling rules using the
kf create-autoscaling-rule app-name CPU min-threshold max-threshold
Delete autoscaling rules
You can delete all autoscaling rules with the
kf delete-autoscaling-rule command. Kf only supports
one autoscaling rule.
kf delete-autoscaling-rules app-name
Enable and disable autoscaling
Autoscaling can be enabled by using
disabled by using
disable-autoscaling. When it is disabled, the
configurations, including limits and rules, are preserved.
kf enable-autoscaling app-name kf disable-autoscaling app-name
Kf Apps support the Kubernetes Horizontal Pod Autoscaler interface and will
therefore work with HPAs created using
Kubernetes HPA policies are less restrictive than Kf’s built-in support for autoscaling.
They include support for:
- Scaling on memory, CPU, or disk usage.
- Scaling based on custom metrics, such as traffic load or queue length.
- Scaling on multiple metrics.
- The ability to tune reactivity to smooth out rapid scaling.
Using custom HPAs with apps
You can follow the Kubernetes HPA walkthrough to learn how to set up autoscalers.
When you create the HPA, make sure to set the
scaleTargetRef to be your application:
apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: app-scaler namespace: SPACE_NAME spec: scaleTargetRef: apiVersion: kf.dev/v1alpha1 kind: App name: APP_NAME minReplicas: 3 maxReplicas: 10 metrics: - type: Resource resource: name: memory target: type: Utilization averageUtilization: 60
- You shouldn’t use Kf autoscaling with an HPA.
- When you use an HPA,
kf appswill show the current number of instances, it won’t show that the App is being autoscaled.