You can use the kubectl patch
method to perform an "in-place" update of a Tanzu Kubernetes cluster. The kubectl patch
method is an alternative to using the kubectl edit
command to perform one of the supported cluster update operations.
About the Kubectl Patch Command
kubectl patch
as described in this topic to update a cluster specifiction so that it conforms with the TKGS v1alpha2 API. For this type of update you should use
kubectl edit
. See
Updating a Tanzu Kubernetes Release After the Cluster Spec Is Converted to the TKGS v1alpha2 API.
kubectl patch
command performs an "in-place" update of a cluster. The purpose of the this command is to provide a method for upgrading Kubernetes versions, and is the approach documented here. For more information on the
kubectl patch
command, see
Update API Objects in Place Using kubectl patch in the Kubernetes documentation.
The approach demonstrated here uses the UNIX shell command read
to take input from the keyboard and assign it to a variable named $PATCH
. The kubectl patch
command invokes the Kubernetes API to update the cluster manifest. The --type=merge
flag indicates that the data contains only those properties that are different from the existing manifest.
Upgrade the Kubernetes Version Using the Patch Method
The most common method to trigger a rolling update is by changing the Kubernetes distribution version for the cluster, using the .spec.distribution.version
and .spec.distribution.fullVersion
properties. You update the version
hint and unset or null out the fullVersion
to avoid a potential version mismatch during discovery.
$ read -r -d '' PATCH <<'EOF' spec: distribution: fullVersion: null # NOTE: Must set to null when updating just the version field version: v1.18.5 EOF
Apply the update using the kubectl patch
command. You must include the quotes around the "$PATCH"
variable to preserve newline characters in the cluster manifest. Replace the TKG-CLUSTER-NAME value with the actual name of your cluster.
kubectl patch --type=merge tanzukubernetescluster TKG-CLUSTER-NAME --patch "$PATCH"
tanzukubernetescluster.run.tanzu.vmware.com/TKG-CLUSTER-NAME patched
Update by the Cluster Changing the VirtualMachineClass for the Nodes Using the Patch Method
Another way to trigger a rolling update of a Tanzu Kubernetes cluster is by changing the VirtualMachineClass
for the node pools, that is, by changing the property .spec.topology.controlPlane.class
or the property .spec.topology.workers.class
.
read -r -d '' PATCH <<'EOF' spec: topology: controlPlane: class: best-effort-xlarge workers: class: best-effort-xlarge EOF
Apply the update using the kubectl patch
command, replacing the variable with the cluster name.
kubectl patch --type=merge tanzukubernetescluster TKG-CLUSTER-NAME --patch "$PATCH"
tanzukubernetescluster.run.tanzu.vmware.com/TKG-CLUSTER-NAME patched
Update the Cluster by Changing the StorageClass for the Nodes Using the Patch Method
Another way to trigger a rolling update of a Tanzu Kubernetes cluster is by changing the StorageClass
for the node pools, that is, by changing the property .spec.topology.controlPlane.storageClass
or the property .spec.topology.workers.storageClass
.
$ read -r -d '' PATCH <<'EOF' spec: topology: controlPlane: storageClass: gc-storage-profile workers: storageClass: gc-storage-profile EOF
kubectl patch
command, replacing the variable with the cluster name.
kubectl patch --type=merge tanzukubernetescluster TKG-CLUSTER-NAME --patch "$PATCH"
tanzukubernetescluster.run.tanzu.vmware.com/TKG-CLUSTER-NAME patched