0
0
GCPcloud~5 mins

Node pools and auto scaling in GCP - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you run apps on Google Kubernetes Engine, you need groups of machines called node pools. Auto scaling helps these groups grow or shrink automatically based on how busy your app is. This saves money and keeps your app running smoothly.
When your app traffic changes a lot during the day and you want to save costs by using fewer machines when traffic is low.
When you want to add different types of machines for special tasks, like some with more memory or CPUs.
When you want Google Cloud to automatically add or remove machines so your app stays fast without manual work.
When you want to test how your app behaves with different numbers of machines.
When you want to keep your app available even if some machines fail by having extra machines ready.
Commands
This command creates a new node pool named 'example-pool' with 3 machines of type e2-medium in the 'example-cluster'. We specify the region to place the machines close to users.
Terminal
gcloud container node-pools create example-pool --cluster example-cluster --num-nodes 3 --machine-type e2-medium --region us-central1
Expected OutputExpected
Created [https://container.googleapis.com/v1/projects/my-project/locations/us-central1/clusters/example-cluster/nodePools/example-pool].
--num-nodes - Sets the initial number of machines in the node pool
--machine-type - Specifies the type of machine for nodes
--region - Defines the region where the cluster and nodes are created
This command enables auto scaling on the 'example-pool' node pool in the 'example-cluster'. It allows the pool to have between 1 and 5 machines depending on workload.
Terminal
gcloud container clusters update example-cluster --region us-central1 --enable-autoscaling --min-nodes 1 --max-nodes 5 --node-pool example-pool
Expected OutputExpected
Updated [https://container.googleapis.com/v1/projects/my-project/locations/us-central1/clusters/example-cluster].
--enable-autoscaling - Turns on auto scaling for the node pool
--min-nodes - Sets the minimum number of nodes to keep running
--max-nodes - Sets the maximum number of nodes allowed
--node-pool - Specifies which node pool to enable autoscaling on
This command lists all node pools in the 'example-cluster' so you can check their status and settings.
Terminal
gcloud container node-pools list --cluster example-cluster --region us-central1
Expected OutputExpected
NAME STATUS MACHINE_TYPE NODE_VERSION AUTOSCALING MIN_NODES MAX_NODES example-pool RUNNING e2-medium 1.26.3-gke.100 ENABLED 1 5
This command shows all the machines (nodes) currently running in your Kubernetes cluster so you can see how many are active.
Terminal
kubectl get nodes
Expected OutputExpected
NAME STATUS ROLES AGE VERSION example-pool-abc123-xyz Ready <none> 10m v1.26.3-gke.100 example-pool-def456-uvw Ready <none> 10m v1.26.3-gke.100 example-pool-ghi789-rst Ready <none> 10m v1.26.3-gke.100
Key Concept

If you remember nothing else from this pattern, remember: node pools group machines with similar settings, and auto scaling lets Google add or remove these machines automatically based on your app's needs.

Common Mistakes
Not enabling auto scaling after creating the node pool
The node pool will stay at the fixed number of nodes and won't adjust to workload changes, wasting resources or causing slowdowns.
Always run the update command with --enable-autoscaling and set min and max nodes to allow scaling.
Setting min-nodes higher than max-nodes
This causes an error because the minimum number of nodes cannot be greater than the maximum.
Ensure min-nodes is less than or equal to max-nodes when enabling auto scaling.
Forgetting to specify the correct region or cluster name
Commands will fail or apply changes to the wrong cluster, causing confusion or errors.
Double-check the cluster name and region flags in every command.
Summary
Create a node pool to group similar machines for your Kubernetes cluster.
Enable auto scaling on the node pool to let Google add or remove machines automatically.
Use commands to check node pool settings and see active machines in your cluster.