What it is
The eksctl command-line tool for creating and managing Kubernetes clusters on Amazon Elastic Kubernetes Service (EKS). You reach for it when you need to provision, update, or delete EKS clusters and their associated resources quickly and repeatably.
Installation
Linux / macOS
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version
Windows (using Chocolatey)
choco install eksctl
eksctl version
Windows (manual download)
- Download the latest release from the eksctl GitHub releases page.
- Extract the
eksctl.exefile. - Add the directory containing
eksctl.exeto your system’s PATH environment variable. - Open a new command prompt or PowerShell window and run:
eksctl version
Core Concepts
- Cluster Configuration File:
eksctlheavily relies on YAML configuration files to define cluster desired state. This allows for declarative, repeatable cluster creation. - Node Groups: EKS clusters run worker nodes.
eksctlmanages these via "Node Groups," which are managed groups of EC2 instances that form your Kubernetes worker fleet. This can include managed node groups (recommended) or self-managed ones. - Addons: EKS supports managed addons like
kube-proxy,coredns, and the AWS VPC CNI.eksctlcan manage the installation and updates of these. - IAM Roles: EKS requires specific IAM roles for the control plane and worker nodes.
eksctlautomatically creates and configures these for you.
Commands / Usage
Cluster Creation
-
Create a basic cluster with default settings:
eksctl create cluster --name my-cluster --region us-west-2Creates an EKS cluster named
my-clusterinus-west-2with a default node group. -
Create a cluster with a specific Kubernetes version and instance type:
eksctl create cluster \ --name my-cluster-v1-27 \ --region eu-central-1 \ --version 1.27 \ --nodegroup-name standard-workers \ --node-type t3.medium \ --nodes 3Creates an EKS cluster named
my-cluster-v1-27ineu-central-1running Kubernetes 1.27, with a node group namedstandard-workersusing 3t3.mediuminstances. -
Create a cluster using a configuration file:
eksctl create cluster -f cluster.yamlCreates an EKS cluster defined by the
cluster.yamlconfiguration file. -
Create a cluster with private networking:
eksctl create cluster \ --name private-cluster \ --region us-east-1 \ --vpc-private-subnets subnet-0abcd1234efgh5678,subnet-0ijkl9876mnop5432 \ --vpc-public-subnets subnet-0wxyz9876uvts5432,subnet-0rqpo8765nmkl4321 \ --without-nodegroupCreates a cluster in
us-east-1using specified private and public subnets, and does not create a default node group (you’ll add one later). -
Create a cluster with Fargate:
eksctl create cluster \ --name fargate-cluster \ --region ap-southeast-2 \ --fargate-profile-name default \ --fargate-profile-selectors namespace=defaultCreates an EKS cluster in
ap-southeast-2with a default Fargate profile that applies to thedefaultnamespace.
Cluster Management
-
List available EKS clusters:
eksctl get cluster --region us-west-2Lists all EKS clusters in the
us-west-2region. -
Describe a cluster:
eksctl get cluster --name my-cluster --region us-west-2 -o jsonGets detailed information about
my-clusterinus-west-2and outputs it as JSON. -
Update a cluster’s Kubernetes version:
eksctl upgrade cluster --name my-cluster --region us-west-2 --version 1.28Initiates an upgrade for
my-clusterinus-west-2to Kubernetes version 1.28. -
Update a cluster’s cloud provider configuration (e.g., tags):
eksctl utils update-cluster-logging --cluster my-cluster --region us-west-2 --enable-audit --enable-api --enable-authenticator --enable-controller-manager --enable-schedulerEnables various control plane logging types for
my-clusterinus-west-2. -
Delete a cluster:
eksctl delete cluster --name my-cluster --region us-west-2Deletes the EKS cluster named
my-clusterinus-west-2, including all associated resources like node groups and the VPC (if created byeksctl).
Node Group Management
-
List node groups for a cluster:
eksctl get nodegroup --cluster my-cluster --region us-west-2Lists all node groups associated with
my-clusterinus-west-2. -
Describe a node group:
eksctl get nodegroup --cluster my-cluster --region us-west-2 --name standard-workers -o jsonGets detailed information about the
standard-workersnode group formy-clusterinus-west-2. -
Create a new node group for an existing cluster:
eksctl create nodegroup \ --cluster my-cluster \ --region us-west-2 \ --name gpu-workers \ --node-type g4dn.xlarge \ --nodes 2 \ --node-private-networking \ --asg-access \ --external-dns-access \ --full-ecr-access \ --alb-ingress-accessAdds a new node group named
gpu-workerswith 2g4dn.xlargeinstances tomy-clusterinus-west-2, granting it specific IAM permissions for common Kubernetes add-ons. -
Update a node group (e.g., scale up/down):
eksctl scale nodegroup \ --cluster my-cluster \ --region us-west-2 \ --name standard-workers \ --nodes 5Scales the
standard-workersnode group formy-clusterinus-west-2to have 5 nodes. -
Update a node group’s instance type (requires recreation):
eksctl replace nodegroup --cluster my-cluster --region us-west-2 --name old-type-workers --new-node-type m5.xlargeReplaces the
old-type-workersnode group with a new one usingm5.xlargeinstances. This will terminate the old nodes and create new ones. -
Delete a node group:
eksctl delete nodegroup --cluster my-cluster --region us-west-2 --name gpu-workersDeletes the
gpu-workersnode group frommy-clusterinus-west-2.
Addon Management
-
List addons for a cluster:
eksctl get addon --cluster my-cluster --region us-west-2Lists all managed addons for
my-clusterinus-west-2. -
Create an addon:
eksctl create addon --cluster my-cluster --region us-west-2 --name vpc-cni --version 1.12.0-eksbuild.1Installs the AWS VPC CNI addon version
1.12.0-eksbuild.1onmy-clusterinus-west-2. -
Update an addon:
eksctl update addon --cluster my-cluster --region us-west-2 --name vpc-cni --version 1.13.1-eksbuild.1Updates the AWS VPC CNI addon on
my-clusterinus-west-2to version1.13.1-eksbuild.1. -
Delete an addon:
eksctl delete addon --cluster my-cluster --region us-west-2 --name vpc-cniDeletes the AWS VPC CNI addon from
my-clusterinus-west-2.
Utilities
-
Enable IAM Identity Center for a cluster:
eksctl utils associate-iam-oidc-provider --cluster my-cluster --region us-west-2 --approveAssociates an IAM OIDC provider with
my-clusterinus-west-2and automatically approves the necessary IAM role changes. -
Get kubeconfig for a cluster:
eksctl utils write-kubeconfig --cluster my-cluster --region us-west-2Updates your local kubeconfig file to point to
my-clusterinus-west-2. -
Enable control plane logging:
eksctl utils update-cluster-logging --cluster my-cluster --region us-west-2 --enable-audit --enable-apiEnables audit and API server logs for
my-clusterinus-west-2. -
Disable control plane logging:
eksctl utils update-cluster-logging --cluster my-cluster --region us-west-2 --disable-audit --disable-apiDisables audit and API server logs for
my-clusterinus-west-2. -
List all IAM roles created by eksctl:
eksctl get iamserviceaccount --cluster my-cluster --region us-west-2Lists IAM service accounts managed by
eksctlformy-cluster.
Configuration File Examples
Basic Cluster:
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: my-basic-cluster
region: us-east-1
version: "1.27"
nodeGroups:
- name: general-workers
instanceType: t3.medium
desiredCapacity: 3
Cluster with Private Networking and Fargate:
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: my-private-fargate-cluster
region: eu-west-2
version: "1.28"
vpc:
subnets:
private:
eu-west-2a:
id: subnet-0123456789abcdef0
eu-west-2b:
id: subnet-0fedcba9876543210
public:
eu-west-2a:
id: subnet-0abcdef0123456789
eu-west-2b:
id: subnet-00123456789abcdef
fargateProfiles:
- name: default-fargate
selectors:
- namespace: default
- namespace: kube-system
Common Patterns
-
Creating a cluster with specific tags:
eksctl create cluster \ --name tagged-cluster \ --region us-west-1 \ --tags '{"Project":"Alpha","Environment":"Dev"}'Creates a cluster and applies the specified tags to AWS resources.
-
Creating a cluster and then immediately configuring kubectl:
eksctl create cluster --name my-app-cluster --region ap-northeast-1 \ && eksctl utils write-kubeconfig --cluster my-app-cluster --region ap-northeast-1Creates the cluster and then automatically sets up your
kubeconfigto use it. -
Scaling a node group and then verifying:
eksctl scale nodegroup --cluster my-cluster --region us-east-1 --name standard --nodes 10 \ && echo "Scaling complete. Verifying..." \ && eksctl get nodegroup --cluster my-cluster --region us-east-1 --name standard -o json | grep -i desiredcapacityScales a node group and then uses
grepto quickly check if the desired capacity has been updated. -
Upgrading a cluster and all its node groups:
eksctl upgrade cluster --name my-cluster --region us-west-2 --version 1.28 --approve \ && eksctl upgrade nodegroup --cluster my-cluster --region us-west-2 --name standard-workers --kubernetes-version 1.28 --approveUpgrades the EKS control plane and then upgrades a specific node group to the new Kubernetes version. Note: Node group upgrades might involve replacing nodes.
-
Creating a cluster with custom IAM policies for node groups:
# cluster.yaml apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: custom-iam-cluster region: us-east-1 nodeGroups: - name: custom-policy-nodes instanceType: t3.medium desiredCapacity: 2 iam: withAddonPolicies: autoScaler: true # Example: enables policies for cluster-autoscaler cloudWatch: true # Example: enables policies for CloudWatch agent # You can also attach custom policies directly: # attachPolicyARNs: # - arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccesseksctl create cluster -f cluster.yamlDefines a node group with pre-defined IAM policies for common addons like
cluster-autoscalerandcloudwatch. -
Draining and deleting a node group before cluster deletion:
eksctl drain nodegroup --cluster my-cluster --region us-west-2 --name old-workers --grace-period=30s --delete-emptydir-data --force \ && eksctl delete nodegroup --cluster my-cluster --region us-west-2 --name old-workersSafely evicts pods from nodes in
old-workersbefore deleting the node group.
Gotchas
- Resource Naming Conflicts:
eksctloften creates resources (like VPCs, subnets, security groups, IAM roles) based on the cluster name. If you delete a cluster and immediately try to create another with the same name in the same region, you might encounter errors due to lingering resources or naming conflicts. Wait a few minutes or manually clean up resources. - IAM Permissions:
eksctlrequires significant IAM permissions to create and manage EKS clusters, VPCs, EC2 instances, and IAM roles. Ensure the AWS credentials you’re using have these permissions. - VPC Creation: By default,
eksctl create clusterwill create a new VPC for your cluster if you don’t specify existing ones. If you want to use an existing VPC, you must provide the subnet IDs using--vpc-public-subnetsand--vpc-private-subnets. delete clusterBehavior:eksctl delete clusteris destructive. It attempts to delete the EKS control plane, all associated node groups, and the VPC and other AWS resources it created. Be very sure before running this command.- Node Group Instance Type Updates: You cannot directly change the instance type of an existing node group. You must create a new node group with the desired instance type and migrate your workloads, or use
eksctl replace nodegroup. --approveFlag: Manyeksctlcommands that make significant changes (like upgrades or deletions) require the--approveflag to proceed. This is a safety mechanism to prevent accidental actions.- Addon Versions: When creating or updating addons, ensure you use valid and compatible versions. Check the EKS documentation for supported addon versions for your Kubernetes version.
- Kubeconfig Merging:
eksctl utils write-kubeconfigmerges the new cluster’s configuration into your existing~/.kube/configfile. If you have many clusters, this file can become large. You might want to manage it more carefully or use tools likekubectxandkubens. - Control Plane Logging: Enabling control plane logging incurs costs. Ensure you understand the pricing and only enable logs you actually need.