1. Autoscaling OCI Instances for Elastic AI Compute


    Autoscaling within the Oracle Cloud Infrastructure (OCI) is a means to automatically adjust the number of compute instances in an instance pool based on performance metrics like CPU utilization. This can be particularly useful for elastic AI compute workloads that may require rapid scaling in response to varying levels of demand.

    To create an autoscaling configuration in OCI using Pulumi, you'll need to define a few key resources:

    1. Compartment: A compartment in OCI is a collection of related resources. Pulumi will need to know which compartment to deploy resources into.

    2. Instance Configuration: This resource specifies the setup of instances you want to launch as part of your instance pool (like the instance shape, image, and other configurations).

    3. Instance Pool: The instance pool manages the lifecycle of instances in your pool based on the instance configuration.

    4. Autoscaling Configuration: This resource defines the rules and policies that govern when to scale out (add) or scale in (remove) instances from the instance pool.

    Below is a Pulumi program written in Python that demonstrates how you could define these resources for an autoscaling instance pool in OCI. The program is structured as follows:

    • Import Statements: We import the required Pulumi OCI package to access OCI resources.
    • Resource Definitions: We start by defining the compartment, instance configuration, instance pool, and autoscaling configuration.
    • Export Statements: Finally, we export any outputs that might be useful later, such as the instance pool ID.

    Let's look at the Pulumi code that sets up autoscaling OCI Instances for elastic AI Compute.

    import pulumi import pulumi_oci as oci # Configuration compartment_id = "ocid1.compartment.oc1..xxxxxx" # Replace with your compartment OCID image_id = "ocid1.image.oc1..xxxxxx" # Replace with the OCID of the image you want to use for instances # Define an OCI compartment compartment = oci.identity.Compartment("aiCompartment", compartment_id=compartment_id) # Define the instance configuration # Specify the setup details like the base image, shape etc. Adjust these settings based on your AI workloads need. instance_configuration = oci.core.InstanceConfiguration("aiInstanceConfiguration", compartment_id=compartment_id, instance_details=oci.core.InstanceConfigurationInstanceDetailsArgs( instance_type="compute", # Specify the type of instance launch_details=oci.core.models.InstanceConfigurationLaunchInstanceDetailsArgs( # Provide the specific details of the instance setup shape="VM.Standard2.1", # This shape determines the number of CPUs, amount of memory source_details=oci.core.models.InstanceConfigurationInstanceSourceViaImageDetailsArgs( image_id=image_id, # Specify the image ID for the instance ), # Include any additional configuration like networking, volumes, etc. ), )) # Define the instance pool using the instance configuration instance_pool = oci.core.InstancePool("aiInstancePool", compartment_id=compartment_id, instance_configuration_id=instance_configuration.id, size=1, # Start with a single instance; autoscaling will adjust this as needed placement_configurations=[oci.core.InstancePoolPlacementConfigurationArgs( # Specify AD-specific configurations availability_domain="Uocm:PHX-AD-1", # Replace with an availability domain in your region primary_subnet_id="ocid1.subnet.oc1..xxxxxx", # Replace with your subnet's OCID )]) # Define an autoscaling configuration autoscaling_configuration = oci.autoscaling.AutoScalingConfiguration("aiAutoscalingConfiguration", # Link the configuration to the instance pool resource_id=instance_pool.id, policies=[oci.autoscaling.AutoScalingPolicyArgs( capacity=oci.autoscaling.AutoScalingCapacityArgs( initial=1, # Initial number of instances when the policy is first applied max=10, # Maximum number of instances that the scaling policy can scale out to min=1), # Minimum number of instances that the scaling policy can scale in to rules=[oci.autoscaling.AutoScalingPolicyRuleArgs( # Define a rule, e.g., if CPU Utilization exceeds 70%, add 2 more instances action=oci.autoscaling.AutoScalingPolicyRuleActionArgs( type="CHANGE_COUNT_BY", value=2, # Number of instances to add or remove ), display_name="ScaleOutOnHighCpuUtilization", metric=oci.autoscaling.MetricArgs( # Configure the metric and the threshold metric_type="CPU_UTILIZATION", threshold=oci.autoscaling.ThresholdArgs( operator="GT", value=70, # The CPU usage threshold ), ), )], # The cooldown period to skip subsequent scale actions after the last scaling action completes cooldown_in_seconds=300, )]) # Export the ID of the instance pool, which can be handy for other operations or outputs pulumi.export("instancePoolId", instance_pool.id)

    This Pulumi program sets up an OCI autoscaling configuration tailored for AI workloads that may need to scale based on CPU utilization. It starts with a base configuration and a single instance in the pool, ready to autoscale between 1 and 10 instances, scaling out by 2 instances when CPU utilization exceeds 70%.

    Remember to replace the strings with actual OCID values for your compartment, image, and subnet. Also, adjust the instance shapes, image IDs, and autoscaling rules based on the specific requirements of your AI workloads and the OCI region you are using.

    This code will not run as-is; you'll need those OCI-specific values substituted in. Moreover, you'll need appropriate permissions and credentials configured for Pulumi to interact with your OCI account. Please ensure you have the OCI CLI installed and configured with the necessary credentials. For more information on Pulumi's support for OCI, refer to Pulumi OCI Documentation.