> ## 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.

# Ensure Alpha Clusters Are Not Used For Production

### More Info:

Alpha clusters are not covered by an SLA and are not production-ready.

### Risk Level

Critical

### Address

Operational Excellence, Performance Efficiency, Reliability, Security

### Compliance Standards

* CIS GKE

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the misconfiguration "Ensure Alpha Clusters Are Not Used For Production" in GCP using GCP console, follow the below steps:

        1. Open the GCP Console and navigate to the Kubernetes Engine page.

        2. Select the cluster that you want to reconfigure.

        3. Click on the Edit button at the top of the page.

        4. In the Edit Cluster page, scroll down to the Node Pools section.

        5. Locate the alpha node pool and click on the trash can icon to delete it.

        6. In the confirmation dialog box, click on Delete to confirm the deletion.

        7. Once the alpha node pool is deleted, click on the Save button at the bottom of the page to save the changes.

        8. Verify that the alpha node pool is no longer present in the cluster.

        By following these steps, you have successfully remediated the misconfiguration "Ensure Alpha Clusters Are Not Used For Production" in GCP using GCP console.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration of using Alpha Clusters for Production in GCP, you can follow the below steps using GCP CLI:

        1. Firstly, ensure that you have the necessary permissions to access and modify the GCP resources.

        2. Open the Cloud Shell in the GCP Console.

        3. Run the below command to list all the available clusters in the current project:

           ```
           gcloud container clusters list
           ```

        4. Identify the Alpha clusters that are being used for production.

        5. Run the below command to upgrade the Alpha cluster to a stable version:

           ```
           gcloud container clusters upgrade [ALPHA_CLUSTER_NAME] --master --cluster-version=[STABLE_VERSION]
           ```

           Here, replace \[ALPHA\_CLUSTER\_NAME] with the name of the Alpha cluster that needs to be upgraded, and \[STABLE\_VERSION] with the latest stable version of Kubernetes.

        6. Once the upgrade is complete, run the below command to ensure that the cluster is no longer an Alpha cluster:

           ```
           gcloud container clusters describe [ALPHA_CLUSTER_NAME] --format="value(currentMasterVersion)"
           ```

           This command will return the current version of the cluster's master. If it is not an Alpha version, then the upgrade was successful.

        7. Finally, ensure that the upgraded cluster is not being used for production by updating the necessary configurations and policies.

        By following these steps, you can remediate the misconfiguration of using Alpha Clusters for Production in GCP using GCP CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration "Ensure Alpha Clusters Are Not Used For Production" in GCP using Python, you can follow the below steps:

        1. First, you need to authenticate and authorize GCP APIs using the Python client library. You can use the below code snippet to authenticate and authorize the APIs:

        ```python theme={null}
        from google.oauth2 import service_account
        from googleapiclient.discovery import build

        # Set the path of your service account credentials JSON file
        SERVICE_ACCOUNT_FILE = 'path/to/your/credentials.json'

        # Define the scopes for the APIs you will be using
        SCOPES = ['https://www.googleapis.com/auth/cloud-platform']

        # Authenticate and authorize the APIs using the credentials file and scopes
        credentials = service_account.Credentials.from_service_account_file(
            SERVICE_ACCOUNT_FILE, scopes=SCOPES)
        service = build('container', 'v1', credentials=credentials)
        ```

        2. Once you have authenticated and authorized the APIs, you can use the `list` method of the `projects.zones.clusters` resource to retrieve the list of all the clusters in your GCP project. You can use the below code snippet to retrieve the list of all clusters:

        ```python theme={null}
        # Set the project ID and zone where your clusters are located
        project_id = 'your-project-id'
        zone = 'us-central1-a'

        # Retrieve the list of all clusters in the specified project and zone
        clusters = service.projects().zones().clusters().list(
            projectId=project_id, zone=zone).execute()
        ```

        3. After retrieving the list of all the clusters, you can iterate through each cluster and check if it is an alpha cluster by checking the `status` field of the cluster. If the `status` field is set to `ALPHA`, then it is an alpha cluster and needs to be remediated. You can use the below code snippet to iterate through each cluster and check its status:

        ```python theme={null}
        # Iterate through each cluster and check its status
        for cluster in clusters.get('clusters', []):
            if cluster.get('status', '').upper() == 'ALPHA':
                # Remediate the cluster by setting its node pool to a non-alpha version
                # You can use the below code snippet to update the node pool of the alpha cluster
                # to a non-alpha version
                node_pool = cluster['nodePools'][0]['name']
                body = {
                    'name': node_pool,
                    'version': '1.18.16-gke.502',
                    'management': {
                        'autoUpgrade': True,
                        'autoRepair': True
                    }
                }
                response = service.projects().zones().clusters().nodePools().update(
                    projectId=project_id, zone=zone, clusterId=cluster['name'], nodePoolId=node_pool, body=body).execute()
        ```

        4. Finally, you can verify that the alpha clusters have been remediated by checking their status again using the `list` method of the `projects.zones.clusters` resource. If the status of the alpha clusters has been changed to a non-alpha version, then the remediation has been successful.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "google_container_cluster" "PRIMARY_PROD_CLUSTER" {
          name     = "PRIMARY_PROD_CLUSTER_NAME"      # replace with your prod cluster name
          project  = "GCP_PROJECT_ID"                 # replace with your GCP project ID
          location = "GCP_REGION_OR_ZONE"             # e.g. "us-central1" or "us-central1-a"

          # Alpha must be disabled for production clusters
          # Remove this argument entirely if it is currently set to true.
          enable_kubernetes_alpha = false

          networking_mode = "VPC_NATIVE"

          remove_default_node_pool = true
          initial_node_count       = 1

          # ...other production-safe settings...
        }

        resource "google_container_node_pool" "PRIMARY_PROD_CLUSTER_DEFAULT_POOL" {
          name    = "PRIMARY_PROD_CLUSTER_DEFAULT_POOL"
          cluster = google_container_cluster.PRIMARY_PROD_CLUSTER.name
          project = google_container_cluster.PRIMARY_PROD_CLUSTER.project
          location = google_container_cluster.PRIMARY_PROD_CLUSTER.location

          node_config {
            machine_type = "e2-standard-4"
            # ...other node config...
          }

          initial_node_count = 3
        }
        ```

        Disabling `enable_kubernetes_alpha` on an existing alpha cluster forces replacement of the `google_container_cluster` resource; Terraform will destroy the alpha cluster and create a new non-alpha cluster, so plan and migrate workloads to avoid downtime.

        For verification, `terraform plan` should show the existing `google_container_cluster` resource being replaced with a new one where `enable_kubernetes_alpha` changes from `true` to `false` (or is removed).
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://cloud.google.com/kubernetes-engine/docs/concepts/alpha-clusters](https://cloud.google.com/kubernetes-engine/docs/concepts/alpha-clusters)
