DevOps: Automating Nodepool Auto-Upgrade Checks Of Kubernetes Cluster Using Shell Script

Author: Ayush Maggo


In this blog, we will explore how to automate the retrieval of details for node pools in a Kubernetes cluster, specifically focusing on those with auto-upgrade enabled or disabled, using shell scripting.

What is Nodepool Auto-Upgrade in the Kubernetes Cluster?

The “Auto-upgrade” feature, found in the management section of a Kubernetes cluster, pertains to the capability of automatically upgrading the nodes within the cluster to the most recent stable version of Kubernetes. This functionality is accessible in different managed Kubernetes services, including Google Kubernetes Engine (GKE) in Google Cloud Platform (GCP), Azure Kubernetes Service (AKS) in Microsoft Azure, and Amazon Elastic Kubernetes Service (EKS) in Amazon Web Services (AWS).

By enabling auto-upgrade for your Kubernetes cluster, you gain the advantage of leveraging the latest advancements in Kubernetes, all while minimizing manual efforts and mitigating the risk associated with running outdated software. This valuable feature plays a crucial role in ensuring the stability, security, and performance of your applications based on Kubernetes.

What is Shell Script?

Shell scripting is a programming approach used to write a sequence of commands for execution by the shell. It involves creating a script that comprises a series of commands and instructions, typically written in a specific language such as Bash or PowerShell.

Shell script files have the extension .sh

Why do we need Shell Script?
  1. Shell scripts are designed to automate repetitive tasks, providing the advantage of time-saving and reducing the need for manual effort.
  2. Whenever you find yourself needing to perform a task repeatedly, utilizing a shell script is a recommended approach.
  3. A shell script has the capability to execute a task faster than a human can.
  4. Shell scripting enhances productivity by enabling the execution of complex operations with simplicity.

Manual way to check whether the Auto-Upgrade is enabled or disabled in a Kubernetes cluster (in GCP).

  • Open the Google Cloud console and navigate to the Kubernetes Engine section.
  • Navigate to the Clusters section and select the specific Kubernetes cluster from the displayed list of clusters.
  • Click on the Nodes tab and open a specific node pool.
  • Now, locate the “Auto-Upgrade” option under the Management section of the node pool. If auto-upgrade is enabled, it will be indicated as “Enabled”. Conversely, if it is disabled, it will be indicated as “Disabled”.
  • By following these steps, you can manually verify whether auto-upgrade is enabled or disabled for your Kubernetes cluster in the Google Cloud Platform.
Why do we use Automation for the retrieval of details of Nodepools with Auto-Upgrade enabled or disabled in a Kubernetes Cluster?

We employ automation to check the auto-upgrade status of a node pool in a cluster, as manual checking can be time-consuming and prone to errors.

By utilizing a shell script, we can automate the process, resulting in time savings and consistent outcomes. The script can be scheduled to run periodically or seamlessly integrated into existing workflows. Manual checking involves the laborious task of inspecting each node pool individually, which can be prone to human error and inefficiency, particularly in larger clusters. Shell scripts offer a reliable and efficient approach to retrieve and monitor the auto-upgrade status, thereby reducing manual effort and minimizing the risk of overlooking or misinterpreting critical information.

Moreover, shell scripting empowers us to execute additional actions or logging based on the auto-upgrade status of each node pool.


  • To utilize the functionality, please ensure that you have a shell environment installed on your system, such as Bash.
  • To proceed, it is essential that you have access to a Kubernetes cluster.
Shell Script to check the Auto-Upgrade status of Nodepools

echo "Enter Project ID"
echo "Enter Cluster Name"
echo "Enter Zone/Region"

# Get list of node pools in the cluster
NODE_POOLS=$(gcloud container node-pools list --project="$PROJECT_ID" --cluster="$CLUSTER_NAME" --zone="$LOCATION" --format="json")

# Iterate through each node pool
echo "$NODE_POOLS" | jq -c '.[]' | while read -r node_pool; do

  # Extract node pool name
  NODE_POOL_NAME=$(echo "$node_pool" | jq -r '.name')

  # Extract auto-upgrade setting
  AUTO_UPGRADE=$(echo "$node_pool" | jq -r '.management.autoUpgrade')

  # Check if auto-upgrade is enabled or disabled
  if [[ "$AUTO_UPGRADE" == "true" ]]; then

  # if enabled
    echo "Auto-Upgrade is enabled for Nodepool: $NODE_POOL_NAME"


  # if disabled
    echo "Auto-Upgrade is disabled for Nodepool: $NODE_POOL_NAME"


Happy Learning!

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.