Prerequisites
Before you begin, you must:
Overview
This topic details how to update the worker node pool by updating the k8s version:
The worker node pool is described by a MachineDeployment resource, which references immutable PreprovisionedMachineTemplate and KubeadmConfigTemplate resources. This topic explains how to patch the MachineDeployment in order to update the node pool in place.
Prepare the environment
-
Set the environment variable to the name you assigned this cluster.
CLUSTER_NAME=my-preprovisioned-cluster
See define infrastructure for information on naming your cluster.
-
If your workload cluster is self-managed, as described in Make the New Cluster Self-Managed, configure
kubectl
to use the kubeconfig for the cluster. If it is not self-managed, skip this step.export KUBECONFIG=${CLUSTER_NAME}.conf
-
Verify that the control plane is already updated.
kubectl get kubeadmcontrolplane ${CLUSTER_NAME}-control-plane
The replicas, ready replicas, and updated replicas counts should be equal, as seen here:
NAME INITIALIZED API SERVER AVAILABLE VERSION REPLICAS READY UPDATED UNAVAILABLE my-preprovisioned-cluster-control-plane true true v1.21.3 1 1 1
-
Define the names of the resources.
export MACHINEDEPLOYMENT_NAME=$(kubectl get machinedeployments --selector=cluster.x-k8s.io/cluster-name=${CLUSTER_NAME} -ojsonpath='{.items[0].metadata.name}')
-
Define the name of your worker template.
export WORKER_TEMPLATE=$(kubectl get PreprovisionedMachineTemplate ${CLUSTER_NAME}-md-0 -ojsonpath='{.metadata.name}')
-
Prepare the patch files.
echo '{}' > md-kubernetes-version-patch.yaml
Prepare to update the Kubernetes version
-
Define the Kubernetes version. Use the letter
v
followed bymajor.minor.patch
version.export KUBERNETES_VERSION=v1.21.6
-
Create a patch file.
cat <<EOF > md-kubernetes-version-patch.yaml apiVersion: cluster.x-k8s.io/v1alpha4 kind: MachineDeployment spec: template: spec: version: ${KUBERNETES_VERSION} strategy: rollingUpdate: maxSurge: 0 maxUnavailable: 0 EOF
-
Update the MachineDeployment
The MachineDeployment is patched to use a new Kubernetes version.
kubectl get machinedeployment ${MACHINEDEPLOYMENT_NAME} --output=yaml \ | kubectl patch --local=true -f- --patch="{\"spec\": {\"template\": {\"spec\": {\"infrastructureRef\": {\"name\": \"$WORKER_TEMPLATE\"} } } } }" --type=merge --output=yaml \ | kubectl patch --local=true -f- --patch-file=md-kubernetes-version-patch.yaml --type=merge --output=yaml \ | kubectl apply -f-
machinedeployment.cluster.x-k8s.io/my-preprovisioned-cluster-md-0 configured
-
Wait for the update to complete. When the number of replicas is equal to the number of updated replicas, the update is complete. You can check the status of the update by running the following command.
kubectl get machinedeployment ${MACHINEDEPLOYMENT_NAME}