Using Schedule-Based Autoscaling
Autoscaling instance pools enables you to effectively manage instance resource use.
An instance pool can have an autoscaling configuration and policies that scale the instance pool in the following ways according to a schedule:
-
Scale out: add instances
-
Scale in: remove instances
-
Lifecycle or power action: stop, start, or reboot instances
When an instance pool scales out or scales in, instances are created or terminated as described in Updating an Instance Pool.
Policies define the schedule for autoscaling and the specific actions to take. An autoscaling configuration can have up to 50 schedule-based autoscaling policies, each with a different schedule and target pool size or lifecycle action. An instance pool can have only one autoscaling configuration.
If you manually change the pool size or lifecycle state as described in Updating an Instance Pool and Stopping and Starting Instances in an Instance Pool, autoscaling resets the pool size or lifecycle state to the value that is set in the policy the next time the scheduled autoscaling policy runs.
Note:
To use autoscaling, ensure that you have installed OCI CLI 3.15.1 or newer and Oracle Cloud Infrastructure Python SDK 2.80.0 or newer.
Multiple Schedule Management
When you create and enable an autoscaling configuration, the Autoscaling service evaluates the schedule rules in the policies in the configuration.
If multiple policies in the same configuration run at the same time, only one lifecycle state policy and one pool size policy will run. The lifecycle state policy runs first.
If multiple lifecycle state policies in the same configuration run at the same time, the policy with the highest priority action runs. The following list shows actions in priority order from highest to lowest priority:
-
Force Reboot
-
Reboot
-
Start
-
Force Stop
If multiple pool size policies in the same configuration run at the same time, the policy that specifies the largest pool size runs.
Creating an Autoscaling Configuration
An autoscaling configuration contains policies that schedule adding or removing instances in a specified pool, or stopping, starting, or rebooting all the instances in the pool.
Using the Compute Web UI
-
In the navigation menu, click Compute, and then click Autoscaling Configurations.
-
Click the Create Autoscaling Configuration button.
-
In the Create Autoscaling Configuration dialog, enter the following information:
-
Name: Enter a name for the autoscaling configuration.
-
Create in Compartment: Select the compartment where you want to create the autoscaling configuration.
-
Instance Pool: Select the instance pool that you want to scale with this autoscaling configuration.
-
Autoscaling Policies: For each policy, provide the following information:
-
Action To Perform: Select either Change Lifecycle State or Scale Pool Size.
-
Policy Name: Enter a name for the policy.
-
Lifecycle Action: If you selected Change Lifecycle State for Action To Perform, then select one of the following states to which to transition all instances of the pool when this policy is executed: Start, Stop, Soft Reset, Reset.
-
Instance Pool Limit: If you selected Scale Pool Size for Action To Perform, then enter a value for the pool size.
-
Enable Schedule: By default, the Schedule Enabled box is selected to enable the policy to execute at the next scheduled time. Uncheck the box to disable this policy.
-
Policy Schedule: Enter values for Minute, Hour, Day Of Month, Month, Day Of Week, and Year. Provide all schedule times in UTC. For more information, see Creating a Schedule-Based Autoscaling Policy.
To add another policy, click the Add Policy button. You can also add policies after the autoscaling configuration is created, as described in Creating a Schedule-Based Autoscaling Policy.
To delete a policy, click the trash can icon for that policy.
-
-
Tagging: (Optional) Add defined or free-form tags for this instance as described in Adding Tags at Resource Creation. Tags can also be applied later.
-
Click Submit.
The details page for the new autoscaling configuration is displayed.
On the details page, ignore the Cooldown Period value. Cooldown period does not apply to schedule-based autoscaling configurations.
The new autoscaling configuration is enabled by default. To disable the configuration, see Updating an Autoscaling Configuration.
-
Using the OCI CLI
-
Get the following information:
-
The OCID of the compartment where you want to create this autoscaling configuration:
oci iam compartment list
-
The OCID of the instance pool that will be managed by this autoscaling configuration:
oci compute-management instance-pool list
-
-
Construct a file that contains all the input for the command.
Use the following command to show the content and format of the command input:
$ oci autoscaling configuration create \ --generate-full-command-json-input > autoscalingCfgCreate.json
The
resource
property is required and is the OCID of the instance pool that will be managed by this autoscaling configuration. Thetype
of this resource must beinstancePool
.At least one policy is required to create an autoscaling configuration. To add policies after the autoscaling configuration is created, see Creating a Schedule-Based Autoscaling Policy.
The optional display name is 1-255 characters, does not need to be unique, and can be updated. If you do not provide a value for
-displayName
, the default name of the autoscaling configuration isautoscalingConfigurationYYYYMMDDhhmmss
, whereinstanceconfigurationYYYYMMDDhhmmss
is the creation date and time.The autoscaling configuration is enabled by default. To disable the configuration, set
isEnabled
tofalse
.Note:
Do not specify values for
coolDownInSeconds
orcapacity
min
ormax
. These properties do not apply to schedule-based autoscaling configurations.The default values for
cool-down-in-seconds
andcapacity
min
andmax
appear in the created autoscaling configuration but are not used for schedule-based autoscaling.The following is an example autoscaling configuration create input file with one policy:
{ "compartmentId": "ocid1.compartment.unique_ID", "displayName": "salesPoolCfg", "policies": { "displayName": "reboot policy", "executionSchedule": { "expression": "0 0 2 ? * 1#1 *", "timezone": "UTC", "type": "cron" }, "policyType": "scheduled", "resourceAction": { "actionType": "power", "action": "SOFTRESET" } }, "resource": { "id": "ocid1.instancePool.unique_ID", "type": "instancePool" } }
-
Run the command to create the autoscaling configuration.
Syntax:
oci autoscaling configuration create --compartment-id compartment_OCID \ --from-json file://input_file.json
Example:
$ oci autoscaling configuration create --c ocid1.compartment.unique_ID \ --from-json file://./salesPoolCfg.json { "data": { "compartment-id": "ocid1.compartment.unique_ID", "cool-down-in-seconds": 300, "defined-tags": {}, "display-name": "salesPoolCfg", "freeform-tags": {}, "id": "ocid1.autoScalingConfiguration.unique_ID", "is-enabled": true, "max-resource-count": null, "min-resource-count": null, "policies": { "capacity": null, "displayName": "reboot policy", "executionSchedule": { "expression": "0 0 2 ? * 1#1 *", "timezone": "UTC", "type": "cron" }, }, "id": "unique_ID", "is-enabled": true, "policy-type": "scheduled", "resourceAction": { "actionType": "power", "action": "SOFTRESET" }, "time-created": "2023-01-25T21:28:56.131801+00:00" }, "resource": { "id": "ocid1.instancePool.unique_ID", "type": "instancePool" }, "time-created": "2023-01-25T21:28:56.140747+00:00" }, "etag": "7c70532a-1d41-4861-a40f-bf840136a9c5" }
Use the
work-requests work-request get
command to check the status of the autoscaling configuration creation.
Creating a Schedule-Based Autoscaling Policy
An autoscaling policy is part of an autoscaling configuration. Each policy of a schedule-based autoscaling configuration has a schedule and either a target pool size or a lifecycle action.
The procedures in this section describe how to create policies separate from creating the autoscaling configuration.
Designing Policies
This section provides some tips for designing and troubleshooting policies.
Create two separate policies to scale a pool in and out or to change the state of the pool between stopped and running.
-
Scale example: One policy specifies a larger size for the pool at the beginning of a high demand period, and a second policy specifies a smaller pool size at the end of the high demand period.
-
State example: One policy stops all instances in the pool at the beginning of a regular compute node maintenance period, and a second policy starts the pool at the end of the maintenance period.
Design the policy schedule as follows:
-
Use
cron
expressions. Autoscaling uses a cron implementation similar to the Quartz cron implementation. All fields require a value. If fields conflict, such as day of month and day of week, use a specific value for one and a question mark for the other. -
Provide all schedule times in UTC.
-
Use an online
cron
expression generator such as Cron Expression Generator & Explainer - Quartz to verify your schedule expressions. -
Ensure that policy schedules do not conflict. See the descriptions in Multiple Schedule Management of which policies run when schedules conflict.
Take the following steps if a policy fails to run, or appears to fail to run:
-
Check that the autoscaling configuration and autoscaling policy are both enabled.
-
Check the schedule expression. Is the policy set to run when you meant for it to run? Remember, all expression times must be provided in UTC.
-
Was the policy set to start instances that were already running, or stop instances that were already stopped?
In addition to a policy conflict, a power action might have been performed on the pool separate from any autoscaling policy. That separate power action could prevent the policy action from succeeding. The policy power action will not be retried.
-
Was the policy set to scale out, but not enough resources were available?
The scale policy sets the pool size, and the pool will continue to attempt to reach that size as resources become available.
-
Is the operation specified by the policy still executing or waiting to execute?
-
Check whether the pool is in the Scaling, Starting, Stopping, or Rebooting state, which indicates that the policy operation is still running.
-
If a state change operation attempts to run while a state change operation is already running on the same pool, the second operation will fail to run.
-
A limited number of pools can be changing state concurrently. If too many other pools are already changing state, then your pool will need to wait to begin changing state. The time to change state is longer when more instances are involved since instances are started, stopped, or rebooted serially.
-
A limited number of pools can be changing size concurrently. If other pools are already changing size, your pool might need to wait to begin scaling. The time to scale is longer when more instances are involved since instances are terminated or created serially. Terminating and creating instances are both background operations and take some time to begin after the pool size has been updated by the policy.
-
Using the Compute Web UI
-
In the navigation menu, click Compute, and then click Autoscaling Configurations.
-
If the configuration to which you want to add a policy is not listed, use the Compartment drop-down menu above the autoscaling configurations list to select the correct compartment.
-
Click the name of the autoscaling configuration to which you want to add a policy.
-
On the autoscaling configuration details page, scroll to the Resources section, click Autoscaling Policies, and click the Create Scheduled Policy button.
-
In the Create policy dialog, enter the following information:
-
Name: Enter a name for the new autoscaling policy.
-
Action to perform: Select Scale pool size or Change lifecycle state of all instances.
-
Scale pool size: Enter the number of instances that the pool should scale to at the scheduled time.
-
Change lifecycle state of all instances: Select the state that all instances in the pool should transition to at the scheduled time.
-
Enable Schedule: By default, the Schedule Enabled box is selected to enable the policy to execute at the next scheduled time. Uncheck the box to disable this policy.
-
-
Execution schedule: Define the schedule for implementing this autoscaling policy. See Designing Policies.
-
-
Click the Submit button.
Using the OCI CLI
-
Get the OCID of the autoscaling configuration where you want to add this autoscaling policy:
oci autoscaling configuration list
-
Construct a file that contains the policy definitions.
Use the following command to show the content and format of the file:
$ oci autoscaling policy create \ --generate-full-command-json-input > autoscalingPolicyCreate.json
Note:
Do not specify values for
capacity
min
ormax
. These properties do not apply to schedule-based autoscaling configurations.The default values for
capacity
min
andmax
appear in the created autoscaling policy but are not used for schedule-based autoscaling.The display name is 1-255 characters, does not need to be unique, and can be updated.
Use the references in Designing Policies for help with setting the policy execution schedule. The
timezone
must beUTC
and thetype
must becron
.The policy is enabled by default.
The policy type must be
scheduled
.The resource action type must be
power
, and the action must be one ofSTOP
,START
,SOFTRESET
,RESET
.The following is an example autoscaling policy create input file:
{ [ { "capacity": { "initial": 10 }, "displayName": "size 10", "executionSchedule": { "expression": "0 0 10 ? 1 2#2 *", "timezone": "UTC", "type": "cron" }, "isEnabled": true, "policyType": "scheduled" }, "capacity": { "initial": 30 }, "displayName": "size 30", "executionSchedule": { "expression": "0 0 7 ? 11 5#1 *", "timezone": "UTC", "type": "cron" }, "isEnabled": true, "policyType": "scheduled" }, { "displayName": "stop policy", "executionSchedule": { "expression": "0 0 7 ? JAN,APR,JUL,OCT 4#3 *", "timezone": "UTC", "type": "cron" }, "isEnabled": true, "policyType": "scheduled", "resourceAction": { "actionType": "power", "action": "STOP" } }, { "displayName": "start policy", "executionSchedule": { "expression": "0 0 13 ? JAN,APR,JUL,OCT 4#3 *", "timezone": "UTC", "type": "cron" }, "isEnabled": true, "policyType": "scheduled", "resourceAction": { "actionType": "power", "action": "START" } } ] }
-
Run the command to create new policies for the specified autoscaling configuration.
Syntax:
oci autoscaling policy create \ --auto-scaling-configuration-id autoscaling_configuration_OCID \ --from-json file://policy_definitions.json --policy-type scheduled
Example:
$ oci autoscaling policy create \ --auto-scaling-configuration-id ocid1.autoscalingConfiguration.unique_ID \ --from-json file://./salesPoolPolicies.json --policy-type scheduled
Use the
work-requests work-request get
command to check the status of the autoscaling policy create command.
Updating an Autoscaling Configuration
You can change the display name of the autoscaling configuration, the tags, and whether the autoscaling configuration is enabled.
To add policies to an autoscaling configuration or update existing policies, see Creating a Schedule-Based Autoscaling Policy and Updating a Schedule-Based Autoscaling Policy.
Using the Compute Web UI
-
In the navigation menu, click Compute, and then click Autoscaling Configurations.
-
If the autoscaling configuration that you want to update is not listed, use the Compartment drop-down menu above the autoscaling configurations list to select the correct compartment.
-
For the autoscaling configuration that you want to update, click the Actions menu and click Edit.
-
In the Update Autoscaling Configuration dialog, make the changes. Ignore the Cooldown Period value.
-
Click the Submit button.
Using the OCI CLI
-
Get the OCID of the autoscaling configuration that you want to update:
oci autoscaling configuration list
-
Run the update command.
Example:
$ oci autoscaling configuration update \ --auto-scaling-configuration-id ocid1.autoscalingConfiguration.unique_ID \ --is-enabled false
Use the
work-requests work-request get
command to check the status of the update operation.
Updating a Schedule-Based Autoscaling Policy
These procedures describe how to update the specified autoscaling policy in the specified autoscaling configuration. You can update the policy display name, either the target pool size or the lifecycle action, and the execution schedule. You can enable or disable the policy.
Using the Compute Web UI, you can delete the policy or add a new policy. To add or delete a policy using the OCI CLI, see Creating a Schedule-Based Autoscaling Policy and Deleting an Autoscaling Policy.
Using the Compute Web UI
-
In the navigation menu, click Compute, and then click Autoscaling Configurations.
-
If the configuration for which you want to update a policy is not listed, use the Compartment drop-down menu above the autoscaling configurations list to select the correct compartment.
-
Click the name of the autoscaling configuration for which you want to update a policy.
-
On the autoscaling configuration details page, scroll to the Resources section and click Autoscaling Policies.
-
For the policy that you want to update, click the Actions menu and then click Edit.
-
In the Update Policy dialog, change the policy information.
-
Click the Submit button.
Using the OCI CLI
-
Get the following information:
-
The OCID of the autoscaling configuration from which you want to remove this autoscaling policy:
oci autoscaling configuration list
-
The ID of the autoscaling policy within that autoscaling configuration:
oci autoscaling configuration get
-
-
Construct a file that contains the updated policy definition.
Use the following command to show the content and format of the file:
$ oci autoscaling policy update \ --generate-full-command-json-input > autoscalingPolicyUpdate.json
See Creating a Schedule-Based Autoscaling Policy for information about policy properties.
-
Run the autoscaling policy update command.
Syntax:
oci autoscaling policy update \ --auto-scaling-configuration-id autoscaling_configuration_OCID \ --auto-scaling-policy-id autoscaling_policy_ID \ --from-json file://policy_definition.json --policy-type scheduled
Example:
$ oci autoscaling policy update \ --auto-scaling-configuration-id ocid1.autoscalingConfiguration.unique_ID \ --auto-scaling-policy-id ID \ --from-json file://./stop_policy.json --policy-type scheduled
Use the
work-requests work-request get
command to check the status of the policy update operation.
Deleting an Autoscaling Configuration
These procedures describe how to delete the specified autoscaling configuration.
Alternatively, you could disable the configuration as described in Updating an Autoscaling Configuration.
Using the Compute Web UI
-
In the navigation menu, click Compute, and then click Autoscaling Configurations.
-
If the autoscaling configuration that you want to delete is not listed, use the Compartment drop-down menu above the autoscaling configurations list to select the correct compartment.
-
For the autoscaling configuration that you want to delete, click the Actions menu and click Delete.
Using the OCI CLI
-
Get the OCID of the autoscaling configuration that you want to delete:
oci autoscaling configuration list
-
Run the autoscaling configuration delete command.
Example:
$ oci autoscaling configuration delete \ --auto-scaling-configuration-id ocid1.autoscalingConfiguration.unique_ID --force
Use the
work-requests work-request get
command to check the status of the delete operation.
Deleting an Autoscaling Policy
These procedures describe how to delete the specified autoscaling policy in the specified autoscaling configuration.
Alternatively, you could disable the policy in the configuration as described in Updating a Schedule-Based Autoscaling Policy.
Using the Compute Web UI
-
In the navigation menu, click Compute, and then click Autoscaling Configurations.
-
If the autoscaling configuration from which you want to delete a policy is not listed, use the Compartment drop-down menu above the autoscaling configurations list to select the correct compartment.
-
Click the name of the autoscaling configuration for which you want to delete a policy.
-
On the autoscaling configuration details page, scroll to the Resources section and click Autoscaling Policies.
-
For the policy that you want to delete, click the Actions menu and then click Delete.
Using the OCI CLI
-
Get the following information:
-
The OCID of the autoscaling configuration from which you want to remove this autoscaling policy:
oci autoscaling configuration list
-
The ID of the autoscaling policy within that autoscaling configuration:
oci autoscaling configuration get
-
-
Run the autoscaling policy delete command.
Syntax:
$ oci autoscaling policy delete \ --auto-scaling-configuration-id ocid1.autoscalingConfiguration.unique_ID \ --auto-scaling-policy-id unique_ID --force
Use the
work-requests work-request get
command to check the status of the policy delete operation.