---
# System prepended metadata

title: Script to change the VM node type on GCP

---

# Script to change the VM node type on GCP

This followed the explaination on https://github.com/fritz-marshal/fritz-deploy#upgrading-the-node-type

## Setup

```
gcloud container clusters get-credentials fritz
gcloud container node-pools list --cluster fritz
# NAME           MACHINE_TYPE   DISK_SIZE_GB  NODE_VERSION
# more-mem-pool  e2-standard-8  100           1.21.14-gke.2700
```
So the working pool name is `more-mem-pool`. I see this machine on [GCP Console](https://console.cloud.google.com/compute/instancesDetail/zones/us-west2-a/instances/gke-fritz-more-mem-pool-f8ea2497-8un5?project=skyportal-206621&pageState=(%22duration%22:(%22groupValue%22:%22PT1H%22,%22customValue%22:null))) (instance id = 2479707377345504634). This machine type `e2-standard-8` has 8 vCPU and 32 GB of memory. 

# Create a New Pool

We'll name our pool `standard-16-pool` and we'll get a 2x beefier machine, ie. `e2-standard-16`.

```
gcloud container node-pools create prod-16-pool \
  --cluster "fritz" \
  --zone "us-west2-a" \
  --num-nodes 1 \
  --scopes "gke-default,https://www.googleapis.com/auth/ndev.clouddns.readwrite" \
  --machine-type=e2-standard-16
```

staging:
```
gcloud container node-pools create staging-2-pool \
  --cluster "fritz-staging" \
  --zone "us-west2-a" \
  --num-nodes 1 \
  --scopes "gke-default,https://www.googleapis.com/auth/ndev.clouddns.readwrite" \
  --machine-type=e2-standard-2
```

Let's check that this pool now exists:
```
gcloud container node-pools list --cluster fritz
```

staging:
```
gcloud container node-pools list --cluster fritz-staging
```

# Cordon off the old nodes

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

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

The cordoned nodes have scheduling disabled, as seen in `kubectl get nodes`.

# Drain the old nodes

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

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

Pods should migrate to the new pool now.


# Delete the old node pool

```
gcloud container node-pools delete standard-16-pool --cluster fritz
```

staging:
```
gcloud container node-pools delete default-pool --cluster fritz-staging
```
