Managing Amazon EKS Clusters with kubectl-eks

kubectl plugin custom command AWS EKS Kubernetes

5 min read | by Jordi Prats

Managing Kubernetes clusters on AWS Elastic Kubernetes Service (EKS) can be challenging, especially when dealing with multiple clusters across different regions and accounts. The kubectl-eks plugin simplifies this process by providing convenient commands to list, inspect, and switch between EKS clusters and their associated resources.

Installation

Pre-built binaries for Linux and macOS (arm64 and x86-64) are available. You can download the binary for your operating system from the releases page on github. Once you have the binary you can install it with:

chmod +x kubectl-eks
mv kubectl-eks /usr/local/bin/

You can make sure it is installed invoking it using kubectl:

kubectl eks --help

If it is installed correctly, you should see the help message for the plugin, otherwise you will see an error message telling you that the command is not recognized:

$ kubectl eks --help
error: unknown command "eks" for "kubectl"

Usage

The kubectl eks plugin provides a set of commands to manage EKS clusters and their associated resources.

To reduce the number of AWS API calls, you need to annotate the accounts where you want to check for EKS clusters by editing the ~/.aws/config file. For example, to annotate the test1 account, add a comment with kubectl-eks-regions and the list of regions you want to scan:

[profile test1]
# kubectl-eks-regions=us-west-2,us-east-1
source_profile=test1creds

This will instruct the plugin to only check the us-west-2 and us-east-1 regions for EKS clusters when you run the kubectl eks list command.

Listing EKS Clusters

To list all EKS clusters across all the annotated AWS profiles and regions, use the kubectl eks list command:

$ kubectl eks list
AWS PROFILE             AWS REGION   CLUSTER NAME              STATUS   VERSION   CREATED               ARN
test1                   us-west-2    test1-west-cluster        ACTIVE   1.21      2022-01-01 00:00:00   arn:aws:eks:us-west-2:123456789012:cluster/test1-west-cluster
test1                   us-east-1    test1-east-cluster        ACTIVE   1.22      2022-02-01 00:00:00   arn:aws:eks:us-east-1:123456789012:cluster/test1-east-cluster

The list of clusters is cached in the ~/.kube/cache/kubectl-eks directory to speed up subsequent calls. You can force a refresh of the cache by using the --refresh flag (-u for short):

$ kubectl eks list --refresh

If you have a large list of clusters, this list can become unusable. You can add filters to the kubectl eks list command to make it more manageable:

  • List clusters that it's name contain some string: --name-contains or -c
  • List clusters that are associated with a specific AWS profile: --profile or -p
  • List clusters that are associated with an AWS profile that contains some string: --profile-contains or -q
  • List clusters that are associated with a specific EKS version: --version or -v
  • List clusters that are in a specific AWS region: --region or -r

Switching EKS Clusters

Having the ARN of the cluster you want to switch to (last column of kubectl eks list), you can use the kubectl eks use command to switch to that cluster:

$ kubectl eks use arn:aws:eks:us-west-2:123456789012:cluster/test1-west-cluster
Switched to EKS cluster "test1-west-cluster" in region "us-west-2" using profile "test1"

Show the current cluster

After some time, you might forget which cluster you are currently using. You can use the kubectl eks command to show the current cluster, it's going to print it in a similar format to the kubectl eks list command:

$ kubectl eks
AWS PROFILE             AWS REGION   CLUSTER NAME              STATUS   VERSION   CREATED               ARN
test1                   us-west-2    test1-west-cluster        ACTIVE   1.21      2022-01-01 00:00:00   arn:aws:eks:us-west-2:123456789012:cluster/test1-west-cluster

Other information about the current EKS cluster

Nodegroups

With the kubectl eks nodegroups you can list the nodegroups associated with the current EKS cluster:

$ kubectl eks nodegroups
NAME      CAPACITY TYPE   RELEASE VERSION         LAUNCH TEMPLATE        INSTANCE TYPE   DESIRED CAPACITY   MAX CAPACITY   MIN CAPACITY   VERSION   STATUS
default   ON_DEMAND       ami-abcd123456789dead   lt-abcd123456789dead   m6g.xlarge      3                  12             3              1.21      ACTIVE

Updates

With the kubectl eks updates you can list the updates for the plugins or details about recent updates applied to a cluster.

$ kubectl eks updates
TYPE            STATUS       ERRORS
LoggingUpdate   Successful

Insights

With the kubectl eks insights you can list the insights for that EKS cluster.

$ kubectl eks insights
ID                                     CATEGORY            STATUS    REASON
ffffffff-beef-1234-abcd-777777777777   UPGRADE_READINESS   PASSING   kube-proxy versions match the cluster control plane version.
eeeeeeee-beef-1234-abcd-bbbbbbbbbbbb   UPGRADE_READINESS   PASSING   All installed EKS add-on versions are compatible with next Kubernetes version.
11111111-beef-1234-abcd-cccccccccccc   UPGRADE_READINESS   PASSING   Node kubelet versions match the cluster control plane version.
aaaaaaaa-beef-1234-abcd-111111111111   UPGRADE_READINESS   PASSING   No deprecated API usage detected within the last 30 days.
bbbbbbbb-beef-1234-abcd-000000000000   UPGRADE_READINESS   PASSING   No cluster health issues detected.

We can get further details using the --show flag and the id of the insight:

$ kubectl eks insights --show aaaaaaaa-beef-1234-abcd-111111111111
Category: UPGRADE_READINESS
Status: PASSING
Description: Checks version of installed EKS add-ons to ensure they are compatible with the next version of Kubernetes.
Recommendation: Upgrade your EKS add-on to a newer version compatible with the next Kubernetes version.
Additional Info:
  * Updating an EKS add-on:
      https://docs.aws.amazon.com/eks/latest/userguide/managing-add-ons.html#updating-an-add-on
No deprecation details found

Source code

The source code for the plugin is available on GitHub pet2cattle/kubectl-eks. Feel free to contribute to the project by opening issues or pull requests.


Posted on 29/01/2025