EKS Cluster and Managed Node Group Commands with the AWS CLI

Cloud Kubernetes control plane connected to managed node groups for inspection and compliance auditing

What You’ll Learn

In this lesson, you will use the AWS CLI to inspect and manage Amazon EKS clusters and managed node groups. You will work with cluster status, Kubernetes versions, node group configuration, and an ordered version-update workflow.

  • Inspect an EKS cluster and list its managed node groups.
  • Read cluster and node group details with focused --query expressions.
  • Understand the relationship between control plane and node group versions.
  • Perform a controlled cluster and node group version update.
Ad

The Concept

Amazon EKS separates a Kubernetes cluster into a managed control plane and one or more data-plane node groups. The control plane runs the Kubernetes API server and other control components. Managed node groups provide the EC2 worker nodes that run Kubernetes workloads.

The AWS CLI’s eks commands let you inspect both parts without opening the AWS Management Console. Common commands include:

  • aws eks describe-cluster for cluster status, version, endpoint, and networking information.
  • aws eks list-nodegroups for the managed node groups belonging to a cluster.
  • aws eks describe-nodegroup for a node group’s version, scaling settings, instance types, and health.
  • aws eks update-cluster-version and aws eks update-nodegroup-version for version updates.
  • aws eks wait for waiting until an asynchronous operation reaches a target state.

These commands are especially useful in deployment scripts, incident investigation, upgrade planning, and CI/CD pipelines. If you need to verify that the command-line tools are installed before starting, you can check AWS CLI command availability.

Most EKS operations are asynchronous. An update command usually starts an operation and returns an update ID; it does not mean that the operation has finished. Use an appropriate waiter or inspect the cluster again before continuing.

Basic Example

The following Bash script inspects a cluster named platform-prod. It displays selected cluster fields, lists managed node groups, and then describes each node group. Replace the cluster name and region with values from your environment.

#!/usr/bin/env bash
set -euo pipefail

cluster_name="platform-prod"
aws_region="us-east-1"

echo "Cluster summary:"
aws eks describe-cluster \
    --name "$cluster_name" \
    --region "$aws_region" \
    --query 'cluster.{Name:name,Status:status,Version:version,Endpoint:endpoint}' \
    --output table

nodegroups=$(aws eks list-nodegroups \
    --cluster-name "$cluster_name" \
    --region "$aws_region" \
    --query 'nodegroups[]' \
    --output text)

if [[ -z "$nodegroups" ]]; then
    echo "No managed node groups were found."
    exit 0
fi

printf '\nManaged node groups:\n'
printf '%s\n' "$nodegroups"

while IFS= read -r nodegroup_name; do
    [[ -z "$nodegroup_name" ]] && continue

    printf '\nNode group: %s\n' "$nodegroup_name"
    aws eks describe-nodegroup \
        --cluster-name "$cluster_name" \
        --nodegroup-name "$nodegroup_name" \
        --region "$aws_region" \
        --query 'nodegroup.{Status:status,Version:version,Release:releaseVersion,Desired:scalingConfig.desired,Min:scalingConfig.min,Max:scalingConfig.max,InstanceTypes:instanceTypes}' \
        --output table
done <<< "$nodegroups"

Expected Output

The exact values depend on your AWS account. The script displays a table for the cluster, a list of managed node group names, and one table for each node group. A healthy cluster and node group normally report an ACTIVE status.

How the Code Works

A process workflow showing AWS CLI inspection of an EKS cluster, listing and describing managed node groups, checking versions and status for compliance, and optionally performing an ordered control plane then node group update with waiters before final verification.
Use AWS CLI to inspect EKS resources, verify node group compliance, and—when approved—upgrade the control plane before managed node groups, waiting for each asynchronous operation to finish.

set -euo pipefail makes the script safer for automation: it stops when a command fails, detects unset variables, and propagates failures through pipelines.

The first describe-cluster command retrieves the complete cluster description, but --query selects only the fields needed for this inspection. The query uses AWS CLI’s JMESPath syntax:

  • cluster.status shows whether the control plane is active.
  • cluster.version shows the Kubernetes version of the control plane.
  • cluster.endpoint shows the Kubernetes API server endpoint.

list-nodegroups returns the names of managed node groups. The command stores those names in nodegroups, then the while loop passes each name to describe-nodegroup.

The node group query selects operationally useful values, including the Kubernetes version, AMI release version, and desired, minimum, and maximum capacity. instanceTypes is an array, so the table output may display it differently depending on the AWS CLI version.

Notice that this script handles only managed node groups. Self-managed nodes, Fargate profiles, and workloads are separate EKS resources. Also, --region is important: an otherwise correct command can report that a cluster does not exist if the CLI is pointed at the wrong region.

Another Example

Upgrading an EKS cluster requires an ordered workflow. The control plane must be upgraded before managed node groups are upgraded to the new Kubernetes version. The following script checks the current version, starts a control plane update when necessary, waits for it to finish, and then starts a node group update.

This example changes AWS resources. Test it in a non-production environment first, and confirm that the target Kubernetes version is supported by your EKS cluster and workload compatibility plan.

#!/usr/bin/env bash
set -euo pipefail

cluster_name="platform-staging"
nodegroup_name="apps"
aws_region="us-east-1"
target_version="1.29"

current_cluster_version=$(aws eks describe-cluster \
    --name "$cluster_name" \
    --region "$aws_region" \
    --query 'cluster.version' \
    --output text)

printf 'Current control plane version: %s\n' "$current_cluster_version"

if [[ "$current_cluster_version" != "$target_version" ]]; then
    echo "Starting the control plane update..."
    aws eks update-cluster-version \
        --name "$cluster_name" \
        --kubernetes-version "$target_version" \
        --region "$aws_region"

    aws eks wait cluster-active \
        --name "$cluster_name" \
        --region "$aws_region"
fi

current_nodegroup_version=$(aws eks describe-nodegroup \
    --cluster-name "$cluster_name" \
    --nodegroup-name "$nodegroup_name" \
    --region "$aws_region" \
    --query 'nodegroup.version' \
    --output text)

printf 'Current node group version: %s\n' "$current_nodegroup_version"

if [[ "$current_nodegroup_version" != "$target_version" ]]; then
    echo "Starting the managed node group update..."
    aws eks update-nodegroup-version \
        --cluster-name "$cluster_name" \
        --nodegroup-name "$nodegroup_name" \
        --kubernetes-version "$target_version" \
        --region "$aws_region"

    aws eks wait nodegroup-active \
        --cluster-name "$cluster_name" \
        --nodegroup-name "$nodegroup_name" \
        --region "$aws_region"
fi

aws eks describe-cluster \
    --name "$cluster_name" \
    --region "$aws_region" \
    --query 'cluster.{Status:status,Version:version}' \
    --output table

aws eks describe-nodegroup \
    --cluster-name "$cluster_name" \
    --nodegroup-name "$nodegroup_name" \
    --region "$aws_region" \
    --query 'nodegroup.{Status:status,Version:version,Release:releaseVersion}' \
    --output table

The update commands may take several minutes. The waiters prevent the script from moving to the next stage until AWS reports the expected state. In a production workflow, you would usually add maintenance-window approval, workload health checks, backup validation, and monitoring around this process.

Common Mistakes

  • Using the wrong region: EKS clusters are regional. Pass the same --region to every command or configure the correct default region.
  • Updating a node group first: Upgrade the control plane before moving a managed node group to a newer Kubernetes version.
  • Assuming the update is complete: update-cluster-version and update-nodegroup-version start asynchronous operations. Use aws eks wait or inspect the resource status.
  • Confusing Kubernetes and AMI versions: The node group’s version is its Kubernetes version, while releaseVersion identifies the EKS-optimized AMI release. They are related but not interchangeable.
  • Forgetting permissions: The IAM identity needs permissions such as eks:DescribeCluster, eks:ListNodegroups, eks:DescribeNodegroup, and the relevant update actions.
  • Updating without compatibility checks: Kubernetes API removals, add-ons, admission controllers, and application assumptions can make a version upgrade unsafe even when AWS accepts the command.

Try It Yourself

Choose a non-production EKS cluster and modify the inspection script so that it:

  • Uses your cluster name and region.
  • Prints only the cluster name, status, and Kubernetes version.
  • Lists each managed node group’s name and status.
  • Uses --output json for the node group details instead of table output.

Compare the result with the AWS Management Console, then try the same commands with an explicitly selected AWS CLI profile by adding --profile your-profile-name.

Challenge

Write a Bash script that audits every managed node group in a specified cluster.

Your script should:

  • Accept the cluster name, region, and expected Kubernetes version as variables.
  • Retrieve all managed node group names.
  • Describe each node group.
  • Print a warning when a node group’s status is not ACTIVE or its Kubernetes version does not match the expected version.
  • Exit with a nonzero status if at least one node group is not compliant.

Do not update resources automatically. This is an audit script, so it should report problems without making changes.

Solution

#!/usr/bin/env bash
set -euo pipefail

cluster_name="platform-prod"
aws_region="us-east-1"
expected_version="1.29"
non_compliant=0

nodegroups=$(aws eks list-nodegroups \
    --cluster-name "$cluster_name" \
    --region "$aws_region" \
    --query 'nodegroups[]' \
    --output text)

if [[ -z "$nodegroups" ]]; then
    echo "No managed node groups were found."
    exit 0
fi

while IFS= read -r nodegroup_name; do
    [[ -z "$nodegroup_name" ]] && continue

    nodegroup_status=$(aws eks describe-nodegroup \
        --cluster-name "$cluster_name" \
        --nodegroup-name "$nodegroup_name" \
        --region "$aws_region" \
        --query 'nodegroup.status' \
        --output text)

    nodegroup_version=$(aws eks describe-nodegroup \
        --cluster-name "$cluster_name" \
        --nodegroup-name "$nodegroup_name" \
        --region "$aws_region" \
        --query 'nodegroup.version' \
        --output text)

    if [[ "$nodegroup_status" == "ACTIVE" && "$nodegroup_version" == "$expected_version" ]]; then
        printf 'PASS: %s is ACTIVE on Kubernetes %s\n' \
            "$nodegroup_name" "$nodegroup_version"
    else
        printf 'WARN: %s has status %s and Kubernetes %s\n' \
            "$nodegroup_name" "$nodegroup_status" "$nodegroup_version"
        non_compliant=1
    fi
done <<< "$nodegroups"

if [[ "$non_compliant" -ne 0 ]]; then
    exit 1
fi

echo "All managed node groups are compliant."

The solution uses the same inspection commands but changes their purpose from display to validation. Each node group’s status and version are captured separately, then checked with a compound Bash condition. The non_compliant flag preserves any failure found during the loop, allowing the script to inspect every node group before returning exit status 1. That status can cause a CI/CD job or scheduled audit to fail.

Key Takeaways

  • describe-cluster, list-nodegroups, and describe-nodegroup provide the core EKS inspection workflow.
  • Use --query to return focused fields instead of processing large AWS CLI responses manually.
  • Upgrade the EKS control plane before upgrading managed node groups.
  • EKS update commands are asynchronous; use waiters or status checks before continuing.
  • Always verify the region, IAM permissions, supported versions, and workload compatibility before making changes.

Leave a Comment

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

Scroll to Top
Ad
Ad
Ad