Upgrading the control plane and worker node pools separately in a Google Distributed Cloud software only for VMware
user cluster lets you validate workload compatibility on individual node pools
and spread upgrades across shorter maintenance windows.

This document is for IT administrators and Operators who manage the
lifecycle of the underlying tech infrastructure. To learn more about common
roles and example tasks that we reference in Google Cloud content, see
[Common GKE user roles and tasks](https://docs.cloud.google.com/kubernetes-engine/enterprise/docs/concepts/roles-tasks.md.txt).
Before you begin, make sure that you're familiar with
[Upgrade overview](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/upgrade-overview.md.txt),
[Upgrade version rules](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/upgrade-version-rules.md.txt),
[Upgrade best practices](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/upgrade-best-practices.md.txt),
and
[Upgrade a cluster](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/upgrading.md.txt).

## Limitations

Upgrading node pools separately from the control plane has the following
limitations:

- This feature is supported for Ubuntu and Container-Optimized OS node
  pools, but not for Windows node pools.

- This feature isn't available when upgrading non-advanced clusters to
  advanced clusters. Non-advanced clusters will be upgraded to advanced
  clusters in 1.33 automatically.

- Version 1.31: this feature isn't available on
  [advanced clusters](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/user-cluster-configuration-file-latest.md.txt#enable-advanced-cluster-field).

- Version 1.32 and higher: this feature is available on advanced clusters.

- Load balancer node pool version must be the same as the cluster version.
  Upgrading a load balancer node pool (a node pool with `enableLoadBalancer: true`)
  separately from the control plane or having version skew isn't supported.

## Why upgrade the control plane and node pools separately?

In certain situations, you might want to upgrade some, but not all, of the
worker node pools in a user cluster:

- You can first upgrade the control plane and a node pool that has light
  traffic or runs your least critical workloads. After you verify that your
  workloads run correctly on the new version, you can upgrade additional node
  pools until all node pools are upgraded.

- Instead of using one large maintenance window for the cluster upgrade, you can
  upgrade the cluster across several maintenance windows. For information about
  estimating the time for a maintenance window, see
  [Estimate the time commitment and plan a maintenance window](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/upgrade-best-practices.md.txt#estimate_the_time_commitment_and_plan_a_maintenance_window).

- You can skip a minor version when upgrading node pools to reduce the number
  of upgrades required to stay on a supported version, which saves time and
  reduces workload disruptions. For more information, see
  [Skip a version when upgrading node pools](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/concepts/skip-version-upgrade.md.txt).

## Before you begin

1. In version 1.29 and later, server-side preflight checks are enabled by
   default. Make sure to
   [review your firewall rules](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/upgrading.md.txt#review_your_firewall_rules)
   to make any needed changes.

2. To upgrade to version 1.28 and later, you must enable
   `kubernetesmetadata.googleapis.com` and grant the
   `kubernetesmetadata.publisher` IAM role to the
   [logging-monitoring service account](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/service-accounts.md.txt#logging_monitoring_service_account).
   For details, see
   [Google API and Identity and Access Management (IAM) requirements](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/upgrading.md.txt#google_api_and_iam_requirements).

3. Make sure the current version of the cluster is at version 1.14 or higher.

## Upgrade the control plane and selected node pools

Upgrading a user cluster's control plane separately from worker node pools is
supported using `gkectl`, the Google Cloud CLI, and Terraform.
You can only use Terraform for the upgrade if you created the user cluster
using Terraform.

### `gkectl`

1. Define the source version and the target version in the following
   placeholder variables. All versions must be the full version number in the
   form `x.y.z-gke.N` such as `1.16.11-gke.25`.

   | Version | Description |
   |---|---|
   | `SOURCE_VERSION` | The current cluster version. |
   | `TARGET_VERSION` | Pick the target version. Select the [recommended patch](https://docs.cloud.google.com/kubernetes-engine/enterprise/docs/version-and-upgrade-support.md.txt#google_cloud_distributed) from the target minor version. |

2. [Upgrade your admin workstation](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/upgrading.md.txt#upgrade_awstation)
   to the target version. Wait for a message indicating the upgrade was
   successful.

3. Import the corresponding OS images to vSphere:

   ```
   gkectl prepare \
     --bundle-path /var/lib/gke/bundles/gke-onprem-vsphere-TARGET_VERSION.tgz \
     --kubeconfig ADMIN_CLUSTER_KUBECONFIG
   ```

   Replace `ADMIN_CLUSTER_KUBECONFIG` with the path of
   your admin cluster `kubeconfig` file.
4. Make the following changes in the user cluster configuration file:

   - Set the `gkeOnPremVersion` field to the target version,
     `TARGET_VERSION`.

   - For each node pool that you want to upgrade, set the
     `nodePools[i].gkeOnPremVersion` field to the empty string.

     - In version 1.28 and later, you can accelerate the node pool upgrade by setting `nodePools[i].updateStrategy.rollingUpdate.maxSurge` [field](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/user-cluster-configuration-file-latest.md.txt#nodepool-updatestrategy-rollingupdate-maxsurge-field) to an integer value greater than 1. When you upgrade nodes with `maxSurge`, multiple nodes upgrade in the same time that it takes to upgrade a single node.
   - For each node pool that you **don't** want to upgrade, set
     `nodePools[i].gkeOnPremVersion` to the source version,
     `SOURCE_VERSION`.
     Note that you cannot hold back load balancer node pools (node pools
     with `enableLoadBalancer: true`); their version must match the
     cluster version.

   The following example shows a portion of the user cluster configuration
   file. It specifies that the control plane and `pool-1` will be upgraded to
   `TARGET_VERSION`, but
   `pool-2` will remain at
   `SOURCE_VERSION`.

   ```yaml
   gkeOnPremVersion: TARGET_VERSION
   ...
   nodePools:
   - name: pool-1
     gkeOnPremVersion: ""
     ...
   - name: pool-2
     gkeOnPremVersion: SOURCE_VERSION
     ...
   ```
5. Upgrade the control plane and selected node pools:

   ```
   gkectl upgrade cluster \
     --kubeconfig ADMIN_CLUSTER_KUBECONFIG \
     --config USER_CLUSTER_CONFIG_FILE
   ```

   Replace `USER_CLUSTER_CONFIG` with the path of your
   user cluster configuration file.

#### Upgrade additional node pools

Using the previous example, suppose everything is working well with `pool-1`,
and now you want to upgrade `pool-2`.

1. In your user cluster configuration file, under `pool-2`, set
   `gkeOnPremVersion` to the empty string:

   ```yaml
   gkeOnPremVersion: TARGET_VERSION
   ...
   nodePools:
   - name: pool-1
     gkeOnPremVersion: ""
     ...
   - name: pool-2
     gkeOnPremVersion: ""
     ...
   ```
2. Run `gkectl update cluster` to apply the change:

   ```
   gkectl update cluster --kubeconfig ADMIN_CLUSTER_KUBECONFIG \
     --config USER_CLUSTER_CONFIG
   ```

### gcloud CLI

Upgrading a user cluster requires some changes to the admin cluster. The
`gcloud container vmware clusters upgrade` command automatically does the
following:

- [Enrolls the admin cluster in the GKE On-Prem API](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/enroll-cluster.md.txt)
  if it isn't already enrolled.

- Downloads and deploys a bundle of components to the admin cluster. The
  version of the components matches the version you specify for the upgrade.
  These components let the admin cluster manage user clusters at that version.

#### Upgrade the control plane

Do the following step to upgrade the user cluster's control plane.

1. Update the gcloud CLI components:

   ```bash
   gcloud components update
   ```
2. Change the upgrade policy on the cluster:

   ```
   gcloud container vmware clusters update USER_CLUSTER_NAME \
     --project=PROJECT_ID \
     --location=REGION \
     --upgrade-policy control-plane-only=True
   ```

   Replace the following:
   - `USER_CLUSTER_NAME`: The name of the user cluster to
     upgrade.

   - `PROJECT_ID`: The ID of the
     [fleet host project](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/multiple-gcp-projects.md.txt#fleet_host_project) in which
     the user cluster is a member. This is the project that you
     specified when the cluster was created. If you created the cluster
     using `gkectl`, this is the project ID in the `gkeConnect.projectID`
     field in the cluster configuration file.

   - `REGION`: The Google Cloud region in which the
     GKE On-Prem API runs and stores its metadata. If you created the cluster
     using an GKE On-Prem API client, this is the region that you selected
     when creating the cluster. If you created the cluster using `gkectl`,
     this is the region that you specified when you enrolled the cluster in
     the GKE On-Prem API.

3. Upgrade the cluster's control plane:

   ```
   gcloud container vmware clusters upgrade USER_CLUSTER_NAME \
     --project=PROJECT_ID \
     --location=REGION \
     --version=TARGET_VERSION
   ```

   Replace `TARGET_VERSION` with the version to upgrade
   to. Select the
   [recommended patch](https://docs.cloud.google.com/kubernetes-engine/enterprise/docs/version-and-upgrade-support.md.txt#google_cloud_distributed)
   from the target minor version.

   The output from the command is similar to the following:

   ```
   Waiting for operation [projects/example-project-12345/locations/us-west1/operations/operation-1679543737105-5f7893fd5bae9-942b3f97-75e59179] to complete.
   ```

   In the example output, the string `operation-1679543737105-5f7893fd5bae9-942b3f97-75e59179`
   is the <var translate="no">OPERATION_ID</var> of the long-running operation.
   You can find out the status of the operation by running the following
   command in another terminal window:

   ```
   gcloud container vmware operations describe OPERATION_ID \
     --project=PROJECT_ID \
     --location=REGION
   ```

#### Upgrade node pools

Do the following steps to upgrade the node pools after the user cluster's
control plane has been upgraded:

> [!IMPORTANT]
> **Important:** When you upgrade a node pool to a new version, you can't modify other node pool attributes, such as display name, labels, or taints, in the same operation. The GKE On-Prem API rejects requests that combine a version upgrade with other attribute changes. If you need to modify other attributes, do so in a separate operation before or after the version upgrade.

1. Get a list of node pools on the user cluster:

   ```
   gcloud container vmware node-pools list
     --cluster=USER_CLUSTER_NAME  \
     --project=PROJECT_ID \
     --location=REGION
   ```
2. For each node pool that you want to upgrade, run the following
   command:

   ```
   gcloud container vmware node-pools update NODE_POOL_NAME \
     --cluster=USER_CLUSTER_NAME  \
     --project=PROJECT_ID \
     --location=REGION \
     --version=TARGET_VERSION
   ```

### Terraform

1. Update the gcloud CLI components:

   ```bash
   gcloud components update
   ```
2. If you haven't already,
   [enroll the admin cluster in the GKE On-Prem API](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/enroll-cluster.md.txt).
   After the cluster is enrolled in the GKE On-Prem API, you don't need to
   do this step again.

3. Download the new version of the components and deploy them in the admin
   cluster:

   ```
   gcloud container vmware admin-clusters update ADMIN_CLUSTER_NAME \
     --project=PROJECT_ID \
     --location=REGION \
     --required-platform-version=TARGET_VERSION
   ```

   Replace the following:
   - `ADMIN_CLUSTER_NAME`: The name of the admin cluster.

   - `PROJECT_ID`: The ID of the
     [fleet host project](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/multiple-gcp-projects.md.txt#fleet_host_project) in which
     the user cluster is a member. This is the project that you
     specified when the cluster was created. If you created the cluster
     using `gkectl`, this is the project ID in the `gkeConnect.projectID`
     field in the cluster configuration file.

   - `REGION`: The Google Cloud region in which the
     GKE On-Prem API runs and stores its metadata. If you created the cluster
     using an GKE On-Prem API client, this is the region that you selected
     when creating the cluster. If you created the cluster using `gkectl`,
     this is the region that you specified when you enrolled the cluster in
     the GKE On-Prem API.

   - `TARGET_VERSION`: The version to upgrade to. Select
     the
     [recommended patch](https://docs.cloud.google.com/kubernetes-engine/enterprise/docs/version-and-upgrade-support.md.txt#google_cloud_distributed)
     from the target minor version.

   This command downloads the version of the components that you specify in
   `--required-platform-version` to the admin cluster, and then deploys the
   components. These components let the admin cluster manage user
   clusters at that version.
4. In the `main.tf` file that you used to create the user cluster, change
   `on_prem_version` in the cluster resource to the new version.

5. Add the following to the cluster resource so that only the control
   plane is upgraded:

   ```yaml
   upgrade_policy {
     control_plane_only = true
   }
   ```
6. Initialize and create the Terraform plan:

   ```bash
   terraform init
   ```

   Terraform installs any needed libraries, such as the Google Cloud
   provider.
7. Review the configuration and make changes if needed:

   ```bash
   terraform plan
   ```
8. Apply the Terraform plan to upgrade the user cluster control plane:

   ```bash
   terraform apply
   ```

#### Upgrade node pools

Do the following steps to upgrade node pools after the user cluster's
control plane has been upgraded:

> [!IMPORTANT]
> **Important:** When you upgrade a node pool to a new version, you can't modify other node pool attributes, such as display name, labels, or taints, in the same operation. The GKE On-Prem API rejects requests that combine a version upgrade with other attribute changes. If you need to modify other attributes, do so in a separate operation before or after the version upgrade.

1. In `main.tf` in the resource for each node pool that you want to
   upgrade, add the following:

   ```
   on_prem_version = "TARGET_VERSION"
   ```

   For example:

       resource "google_gkeonprem_vmware_node_pool" "nodepool-basic" {
       name = "my-nodepool"
       location = "us-west1"
       vmware_cluster = google_gkeonprem_vmware_cluster.default-basic.name
       config {
         replicas = 3
         image_type = "ubuntu_containerd"
         enable_load_balancer = false
       }
       on_prem_version = "1.16.0-gke.0"
       }

2. Initialize and create the Terraform plan:

   ```bash
   terraform init
   ```
3. Review the configuration and make changes if needed:

   ```bash
   terraform plan
   ```
4. Apply the Terraform plan to upgrade the node pools:

   ```bash
   terraform apply
   ```

## Troubleshooting

If you encounter an issue after upgrading a node pool, you can roll back to
the previous version. For more information, see
[Roll back a node pool after an upgrade](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/troubleshooting/create-upgrade.md.txt#roll-back-node-pool).