> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Autoscaling Profile For Clusters Should Be Set To Optimize_Utilization or Balanced

### More Info:

Ensure that cluster autoscaling profile is set to OPTIMIZE\_UTILIZATION or BALANCED for optimal resource utilization

### Risk Level

Medium

### Address

Operational Excellence, Performance Efficiency, Reliability, Security

### Compliance Standards

* Cloudanix Best Practice

### Triage and Remediation

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the Autoscaling Profile for Clusters misconfiguration in GCP using GCP console, follow these steps:

        1. Open the GCP console and navigate to the Kubernetes Engine page.
        2. Select the cluster that you want to remediate.
        3. Click on "Edit" button at the top of the page.
        4. In the "Node pools" section, click on the name of the node pool that you want to remediate.
        5. Scroll down to the "Autoscaling" section and click on "Edit".
        6. In the "Autoscaling mode" section, select either "Optimize utilization" or "Balanced" depending on your requirements.
        7. Click on "Save" to apply the changes.

        Once you have completed these steps, the Autoscaling Profile for Clusters misconfiguration will be remediated in GCP.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration "Autoscaling Profile For Clusters Should Be Set To Optimize\_Utilization or Balanced" for GCP using GCP CLI, you can follow the below steps:

        Step 1: Open the Cloud Shell in your GCP console.

        Step 2: Run the following command to list all the existing node pool configurations in the cluster:

        ```
        gcloud container node-pools list --cluster <cluster-name>
        ```

        Step 3: Choose the node pool for which you want to set the autoscaling profile.

        Step 4: Run the following command to set the autoscaling profile to "optimize-utilization":

        ```
        gcloud container node-pools update <node-pool-name> --cluster <cluster-name> --autoscaling-profile optimize-utilization
        ```

        OR

        Run the following command to set the autoscaling profile to "balanced":

        ```
        gcloud container node-pools update <node-pool-name> --cluster <cluster-name> --autoscaling-profile balanced
        ```

        Note: Replace `<cluster-name>` and `<node-pool-name>` with the actual names of your cluster and node pool respectively.

        Step 5: Verify that the autoscaling profile has been set correctly by running the following command:

        ```
        gcloud container node-pools describe <node-pool-name> --cluster <cluster-name> --format="value(config.autoscaling.autoprovisioningProfile)"
        ```

        This should return either "optimize-utilization" or "balanced" depending on which profile you chose to set.

        By following these steps, you can remediate the misconfiguration "Autoscaling Profile For Clusters Should Be Set To Optimize\_Utilization or Balanced" for GCP using GCP CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration "Autoscaling Profile For Clusters Should Be Set To Optimize\_Utilization or Balanced" in GCP, you can follow the below steps using Python:

        1. Import the required libraries:

        ```
        from google.cloud import dataproc_v1 as dataproc
        from google.protobuf import field_mask_pb2 as field_mask
        ```

        2. Set the project ID, region, and cluster name:

        ```
        project_id = "your-project-id"
        region = "your-region"
        cluster_name = "your-cluster-name"
        ```

        3. Create a client object:

        ```
        client = dataproc.ClusterControllerClient()
        ```

        4. Get the current cluster configuration:

        ```
        cluster = client.get_cluster(project_id, region, cluster_name)
        ```

        5. Update the autoscaling configuration with the desired profile:

        ```
        autoscaling_config = cluster.config.software_config.autoscaling_config
        autoscaling_config.policy_uri = ""
        autoscaling_config.secondary_worker_config = {}
        autoscaling_config.policy_uri = ""
        autoscaling_config.worker_config.autoscaling_policy.policy_uri = ""
        autoscaling_config.worker_config.autoscaling_policy.basic_algorithm = "BASIC_AUTOSCALING"
        autoscaling_config.worker_config.autoscaling_policy.yarn_config.graceful_decommission_timeout = {}
        autoscaling_config.worker_config.autoscaling_policy.yarn_config.scale_up_factor = 0.5
        autoscaling_config.worker_config.autoscaling_policy.yarn_config.scale_down_factor = 1.0
        autoscaling_config.worker_config.autoscaling_policy.yarn_config.scale_down_min_worker_fraction = 0.8
        autoscaling_config.secondary_worker_config.autoscaling_policy.policy_uri = ""
        autoscaling_config.secondary_worker_config.autoscaling_policy.basic_algorithm = "BASIC_AUTOSCALING"
        autoscaling_config.secondary_worker_config.autoscaling_policy.yarn_config.graceful_decommission_timeout = {}
        autoscaling_config.secondary_worker_config.autoscaling_policy.yarn_config.scale_up_factor = 0.5
        autoscaling_config.secondary_worker_config.autoscaling_policy.yarn_config.scale_down_factor = 1.0
        autoscaling_config.secondary_worker_config.autoscaling_policy.yarn_config.scale_down_min_worker_fraction = 0.8
        ```

        6. Update the cluster configuration:

        ```
        update_mask = field_mask.FieldMask(paths=["config.software_config.autoscaling_config"])
        client.update_cluster(project_id, region, cluster_name, cluster, update_mask)
        ```

        This will update the autoscaling configuration for the specified GCP cluster with the desired profile.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "google_container_cluster" "PRIMARY_CLUSTER" {
          name               = "PRIMARY_CLUSTER_NAME"        # replace with your cluster name
          location           = "PRIMARY_CLUSTER_LOCATION"    # replace with your region or zone
          initial_node_count = 1

          # Existing cluster config ...
          # networking, master_auth, node_config, etc.

          autoscaling {
            enable_node_autoprovisioning = true               # keep/adjust based on your setup

            # Set to one of the allowed values: "OPTIMIZE_UTILIZATION" or "BALANCED"
            autoscaling_profile = "OPTIMIZE_UTILIZATION"
            # autoscaling_profile = "BALANCED"
          }
        }
        ```

        This change is an in‑place update for an existing GKE cluster and does not force replacement.

        For verification, `terraform plan` should show a single in‑place change on `google_container_cluster.PRIMARY_CLUSTER` with `autoscaling.0.autoscaling_profile` changing from its current value (for example `"STANDARD"`) to `"OPTIMIZE_UTILIZATION"` or `"BALANCED"`.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1/projects.locations.clusters#Cluster.AutoscalingProfile](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1/projects.locations.clusters#Cluster.AutoscalingProfile)
