Change nodepool instance type in GKE

In GKE, sometimes the instance type you have chose to deploy your application might not be enough and you may need to change it. If that is what you need then follow along. Here, I already have setup gcloud and changing the instance type to custom machine with 4 CPUs and 16GiB RAM.

Create a separate node-pool

gcloud container node-pools create medium-pool --disk-size=30 --cluster cluster-1 --machine-type custom-4-16384 --enable-autoscaling --num-nodes 1 --min-nodes 1 --max-nodes 5

Here,

medium-pool is the name of nodepool
--disk-size is the size of disk for each node
--cluster is the existing cluster name
--machine-type is the name of custom machine in the form of custom-{cpu}-{ram in mib}

Cordon each node. This means you are marking nodes as unschedulable.

for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool=old-pool -o=name); do
   kubectl cordon "$node";
 done

Evict the pods. Take caution.

for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool=old-pool -o=name); do
   kubectl drain --force --ignore-daemonsets --delete-local-data --grace-period=10 "$node";
 done

where,

old-pool is the name of old pool which we will remove

Remove old node pool

gcloud container node-pools delete old-pool --cluster cluster-1

List the nodepool, you should have only one running

gcloud container node-pools list --cluster cluster-1

 NAME         MACHINE_TYPE    DISK_SIZE_GB  NODE_VERSION
 medium-pool  custom-4-16384  30            1.18.17-gke.100

Read details: https://cloud.google.com/kubernetes-engine/docs/tutorials/migrating-node-pool

Leave a Reply

Your email address will not be published. Required fields are marked *