Using Cloud Foundry App Autoscaler with IBM® Cloud Private Cloud Foundry
You can integrate your IBM® Cloud Private Cloud Foundry application with App Autoscaler.
App Autoscaler is a marketplace service that you can use to control the cost of running apps while you maintain app performance.
To balance app performance and cost, space developers can use App Autoscaler to perform the following tasks:
- Configure rules that adjust instance counts based on metrics thresholds, such as CPU usage.
- Modify the maximum and minimum number of instances for an app, either manually or by following a schedule.
App Autoscaler uses five releases:
cfp-cf-releaseunboundpostgrescf-routing-releaseapp-autoscaler-release
The cfp-cf-release and unbound releases are provided with IBM Cloud Private Cloud Foundry. You must download and move the postgres and cf-routing-release releases into directories on the inception container. The App Autoscaler release is included in the app-autoscaler-release/src directory.
Note: These instructions assume that you do not already have a database set up for autoscaling. If you already have a database set up, make sure that you configure the manifests/db-stub-override.yml file to map the
addresses and tables to the correct database. In addition, make sure that your default_db value in the manifests/property-overrides.yml file is linked to the correct database.
Prerequisites for installing App Autoscaler
- Install the Bosh and IBM Cloud Private Cloud Foundry command line interfaces. For more information on these command line interfaces, see Command line interfaces for IBM® Cloud Private Cloud Foundry.
- Ensure that you have internet access when you make the extension so that you can download the
postgresandcf-routing-releasereleases.- Download
postgresfrom Postgres v17.
- Download
cf-routing-releasefrom cf-routing-release v162.
- Download
- Configure the static IP address for your database (customization is required to support multiple databases).
- Determine the static IP addresses to use.
- Open the
cloud-config.ymland add the static IP addresses to it. - Adjust the
networks.subnets.reservedarray to include the new static IP address, as well as seven additional addresses for the other autoscale jobs that are required. A total of eight IP addresses are required. - Redeploy the
cloud-config.ymlfile to include the updated IP addresses by running the following command:bosh -e ENVIRONMENT_NAME update-cloud-config /data/CloudFoundry/cloud-config.yml
Installing App Autoscaler
You deploy the App Autoscaler through the Platform Configuration Manager as an extension. For more information about extensions, see Using extensions in IBM® Cloud Private Cloud Foundry
-
Clone the Git repository that contains the App Autoscaler source code in the inception container host. Run the following command to clone the Git repository:
git clone https://github.com/jnpacker/app-autoscaler-release.git -
From a terminal, change to the
app-autoscaler-releasefolder in the cloned files:cd app-autoscaler-release -
Review the
manifest/property-override.ymlfile and customize all required property values. Confirm that the ports, user names, and passwords are correct. Review and update the following properties:cf_properties.apidefault_db.addressservice_broker_properties.uriservice_broker_properties.portservice_broker_properties.usernameservice_broker_properties.passworddefault_db.password
-
Create the extension by running the following command in your terminal:
make extension -
Copy the
app-autoscaler-extension.zipfile to the server that is running the installation container for IBM Cloud Private Cloud Foundry. - Open an interactive
bashshell on the server. -
From the
bashshell, register the extension. You must be in the same directory asinstall.sh. Register the extension by running the following command:./cm extension -e app-autoscaler register -p ./app-autoscaler-extension.zip -
From the
bashshell, deploy the extension by running the following command:./cm extension -e app-autoscaler deploy -
Confirm that all the steps have the
SUCCEEDEDstatus. Run the following command and review the output:./cm states -e app-autoscaler
Registering App Autoscaler
-
Register the App Autoscaler service. Log in to {{site.data.keyword.cf_notm}} as the admin user and run the following command:
cf create-service-broker autoscaler <brokerUserName> <brokerPassword> <brokerURL>In this command:
- The
<brokerUserName>is the user name to authenticate with the service broker. - The
<brokerPassword>is the password to authenticate with the service broker. - The
<brokerURL>is the URL of the service broker.
The default
<brokerUserName>value isusername, the default<brokerPassword>value ispassword, and the default<brokerURL>value ishttp://autoscalerservicebroker.YOUR_DOMAIN.If you used the default values, run the following command:
cf create-service-broker autoscaler username password http://autoscalerservicebroker.YOUR_DOMAIN - The
-
To use the service to auto-scale your applications, log in to {{site.data.keyword.cf_notm}} as the admin user, and enable access to the service for your orgs. Run the following command to enable service access to all or specific orgs.
cf enable-service-access autoscaler -o <org>Where
<org>is the org or orgs whose members can use the service. -
As a user with the space developer role, create the service instance.
cf create-service autoscaler autoscaler-free-plan <service_instance_name>Where
<service_instance_name>is the name that you assign to the service instance.
Creating the autoscaling policy.
-
Create the autoscaling policy file. The autoscaling policy file is a JSON formatted file that contains the parameters that define the autoscaling rules. The JSON file resembles the following code:
{ "instance_min_count": 1, "instance_max_count": 5, "scaling_rules": [{ "metric_type": "memoryutil", "stat_window_secs": 300, "breach_duration_secs": 600, "threshold": 30, "operator": "<", "cool_down_secs": 300, "adjustment": "-1" }, { "metric_type": "memoryutil", "stat_window_secs": 300, "breach_duration_secs": 600, "threshold": 55, "operator": ">=", "cool_down_secs": 300, "adjustment": "+1" }], "schedules": { "timezone": "America/Los_Angeles", "recurring_schedule": [{ "start_time": "01:00", "end_time": "23:00", "days_of_week": [ 1, 2, 3, 4, 5, 6, 7 ], "instance_min_count": 1, "instance_max_count": 5, "initial_min_instance_count": 5 }], "specific_date": [{ "start_date_time": "2016-06-02T10:00", "end_date_time": "2018-06-15T13:59", "instance_min_count": 1, "instance_max_count": 4, "initial_min_instance_count": 1 }] } }This file contains several sections. In it, you define the
instance_min_countvalue, which is the minimum number of instances, and theinstance_max_count, which is the maximum number of instances. In thescaling_rulessection, you can define multiple scaling criteria. In theschedulessection, you can define recurring schedules based on the day of the week or single schedules for a particular day or time range. While you can provide multiple scaling rules or schedules, each of these definitions must contain all of the specified parameters. The following table provides more information about these parameters:
| Parameter | Description | Value |
|---|---|---|
instance_min_count |
The minimum number of application instances. | Positive integer |
instance_max_count |
The maximum number of application instances. | Positive integer |
scaling_rules |
The set of rules that define when new applications are created or removed. | Array |
metric_type |
|
|
stat_window_secs |
Positive integer (in seconds) | |
breach_duration_secs |
Positive integer (in seconds) | |
threshold |
The limit for when to change the number of application instances. | Positive integer |
operator |
|
|
cool_down_secs |
Positive integer (in seconds) | |
adjustment |
The amount of change to the number of instances. You can increase and decrease by a number of instances or a percent of instances. |
|
schedules |
The set of rules that define how new applications are created or removed at different times. | Array |
timezone |
The time zone of the server. | |
recurring_schedule |
||
start_time |
The time of day that the rules start to be applied. | 24-hour time, such as 01:00 |
end_time |
The time of day that the rules are no longer applied. | 24-hour time, such as 023:00 |
days_of_week |
The days of the week to which the schedule applies. Here, Sunday is represented as 1. |
1-7 |
initial_min_instance_count |
The minimum number of instances at the start of the time period. | Positive integer |
specific_date |
The autoscaling policy to apply for a specific time range. | Array |
start_date_time |
The time to start to apply this policy. | Date and time in the following format: <four_digit_year>-<two_digit_month>-<two_digit_day>T<hour>:<minute>, eg 2018-06-15T13:59 |
end_date_time |
The time to end this policy. | Date and time in the following format: <four_digit_year>-<two_digit_month>-<two_digit_day>T<hour>:<minute>, eg 2018-06-15T13:59 |
-
As a user with the space developer role, bind an existing application to the service instance.
cf bind-service <app_name> <service_instance_name> -c <policy>In this command:
- The
<app_name>is the name of the application to autoscale. - The
<service_instance_name>is the name of the service instance for the App Autoscaler. - The
<policy>is the path to the policy file to apply, such as/data/extension/custom/app-autoscaler/example/example-policy.json.
Now, your service is bound to your application, and it automatically scales to the requirements that are defined in the
policy.jsonfile. - The
Removing the service
Complete the following steps to remove the service.
- Log in to {{site.data.keyword.cf_notm}} as the admin user.
- Run the following commands:
cf purge-service-offering autoscaler ; \ cf delete-service-broker autoscaler
Troubleshooting the App Autoscaler
Failure in creating a release
Symptoms
When you deploy the App Autoscaler, the following error message is displayed:
Building a release from directory '/data/extensions/custom/app-autoscaler':
Compressing staging directory:
Shelling out to tar:
Running command: 'tar czf /data/home/.bosh/tmp/bosh-platform-disk-TarballCompressor-CompressSpecificFilesInDir114079115 -C /data/home/.bosh/tmp/bosh-resource-archive204470236 .', stdout: '', stderr: '
gzip: stdout: No space left on device
':
signal: broken pipe
Exit code 1
state:Create Release
Causes
Your /data/home/.bosh/tmp directory is full.
Resolving the problem
Clear the BOSH temporary directory by running the following command:
rm -rf /data/home/.bosh/tmp
Failure to access a URL during release creation
Symptoms
When you deploy the App Autoscaler, the following error message is displayed:
org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute INFO: Retrying request to {s}->https://repo.spring.io:443
Causes
The inception container has trouble connecting to some secure repositories.
Resolving the problem
- Open the
pom.xmlfile in the/data/extensions/custom/app-autoscaler/src/app-autoscaler/scheduler/folder. - Change all
httpsreferences tohttp. - Run the deployment command again:
/opt/ibm/cloud/bin/cm extension -e app-autoscaler deploy