How to use the command eksctl (with examples)

How to use the command eksctl (with examples)

eksctl is the official CLI for Amazon Elastic Kubernetes Service (EKS). It provides an easy and efficient way to create and manage Kubernetes clusters on AWS.

Use case 1: Create a basic cluster

Code:

eksctl create cluster

Motivation:

This use case is useful when you want to quickly create a basic Kubernetes cluster on AWS EKS without providing any additional configuration options.

Explanation:

  • eksctl create cluster is the command used to create a cluster.
  • This command does not require any additional arguments, as it uses default values for cluster configuration.
  • When executed, it will create a new Kubernetes cluster on AWS EKS.

Example output:

[ℹ]  creating AWS EKS cluster "cluster-name" in "region"
[ℹ]  creating ServiceRole stack "eksctl-cluster-name-addon-iamserviceaccount-default"
[ℹ]  creating control plane security group "eksctl-cluster-name-cluster"
[ℹ]  creating VPC stack "eksctl-cluster-name-vpc-eksctl-clus-2d8eb4"
[ℹ]  creating IAM role "eksctl-cluster-name-cluster"
[ℹ]  downloading kubeconfig file for cluster "cluster-name"
[ℹ]  creating nodegroup stack "eksctl-cluster-name-nodegroup-default"
[ℹ]  --nodes-min=2 was set automatically for nodegroup default
[ℹ]  --nodes-max=2 was set automatically for nodegroup default
[ℹ]  You can also run 'eksctl utils write-kubeconfig --cluster=cluster-name --region=region' to store the kubeconfig file away or use 'kubectl' directly
[ℹ]  nodegroup "default" has 0 node(s)
[ℹ]  waiting for at least 2 node(s) to become ready in "default"
[ℹ]  nodegroup "default" has 2 node(s)
[ℹ]  node "ip-192-168-10-1.ec2.internal" is ready
[ℹ]  node "ip-192-168-20-1.ec2.internal" is ready
[ℹ]  kubectl command should work with "<config-filepath>"
[ℹ]  you can also use --kubeconfig=<path> flag
[✔]  EKS cluster "cluster-name" in "region" is ready

Use case 2: List the details about a cluster or all of the clusters

Code:

eksctl get cluster --name=name --region=region

Motivation:

This use case is helpful when you need to gather information about a specific cluster or all available clusters in a particular AWS region.

Explanation:

  • eksctl get cluster is the command used to retrieve the details about a cluster or all clusters.
  • The --name flag specifies the name of the cluster to retrieve details for.
  • The --region flag specifies the AWS region in which the cluster is located.

Example output (when retrieving details for a specific cluster):

[ℹ]  eksctl version 0.70.0
[ℹ]  using region <region>
[ℹ]  searching cluster "cluster-name" in region "<region>"
NAME			REGION	EKSCTL CREATED
cluster-name	<region>	True

Example output (when listing details for all available clusters in a region):

[ℹ]  eksctl version 0.70.0
[ℹ]  using region <region>
[ℹ]  AWS region "<region>"
[ℹ]  No clusters found

Use case 3: Create a cluster passing all configuration information in a file

Code:

eksctl create cluster --config-file=path/to/file

Motivation:

This use case is useful when you have a custom configuration file containing all the necessary information to create an EKS cluster and want to use it for cluster creation.

Explanation:

  • eksctl create cluster is the command used to create a cluster.
  • The --config-file flag specifies the path to the configuration file containing cluster information.
  • The configuration file should contain all the necessary information required to create the EKS cluster, such as cluster name, region, nodegroup details, and other advanced configuration options.

Example output:

[ℹ]  using region "<region>"
[ℹ]  Fetched CloudFormation template.
[ℹ]  building cluster stack "<cluster-name>"
[ℹ]  deploying stack: ArgumentsExecutor.
[ℹ]  waiting for CloudFormation stack "<cluster-name>"
...
[✔]  created cluster "<cluster-name>": <cluster-id>
[ℹ]  The 'coredns' addon is currently in alpha and automatically enabled for clusters that meet the following criteria: Kubernetes version: >= 1.11, < 1.12
...
[ℹ]  nodegroup "ng-<nodegroup-id>" has 0 node(s)
[ℹ]  waiting for at least 2 node(s) to become ready in "ng-<nodegroup-id>"
[ℹ]  nodegroup "ng-<nodegroup-id>" has 2 node(s)
[ℹ]  node "ip-192-168-10-1.ec2.internal" is ready
[ℹ]  node "ip-192-168-20-1.ec2.internal" is ready
[ℹ]  kubectl command should work with "<config-filepath>"
[ℹ]  you can also use --kubeconfig=<path> flag

Use case 4: Create a cluster using a configuration file and skip creating nodegroups until later

Code:

eksctl create cluster --config-file=<path> --without-nodegroup

Motivation:

This use case is beneficial when you want to create the EKS cluster with the initial cluster infrastructure but skip creating the nodegroups until a later stage.

Explanation:

  • eksctl create cluster is the command used to create a cluster.
  • The --config-file flag specifies the path to the configuration file containing cluster information.
  • The --without-nodegroup flag instructs eksctl to skip creating the nodegroups defined in the configuration file.

Example output:

[ℹ]  using region "<region>"
[ℹ]  Fetched CloudFormation template.
[ℹ]  building cluster stack "<cluster-name>"
[ℹ]  deploying stack: ArgumentsExecutor.
[ℹ]  waiting for CloudFormation stack "<cluster-name>"
...
[✔]  created cluster "<cluster-name>": <cluster-id>
[ℹ]  The 'coredns' addon is currently in alpha and automatically enabled for clusters that meet the following criteria: Kubernetes version: >= 1.11, < 1.12
...
[ℹ]  nodegroup "ng-<nodegroup-id>" has 0 node(s)
[ℹ]  waiting for at least 2 node(s) to become ready in "ng-<nodegroup-id>"
[ℹ]  nodegroup "ng-<nodegroup-id>" has 2 node(s)
[ℹ]  node "ip-192-168-10-1.ec2.internal" is ready
[ℹ]  node "ip-192-168-20-1.ec2.internal" is ready
[ℹ]  run 'eksctl create nodegroup --config-file=path/to/file' to create a nodegroup
[ℹ]  kubectl command should work with "<config-filepath>"
[ℹ]  you can also use --kubeconfig=<path> flag

Use case 5: Delete a cluster

Code:

eksctl delete cluster --name=name --region=region

Motivation:

This use case is helpful when you no longer need an existing EKS cluster and want to remove it from your AWS account.

Explanation:

  • eksctl delete cluster is the command used to delete a cluster.
  • The --name flag specifies the name of the cluster to be deleted.
  • The --region flag specifies the AWS region in which the cluster is located.

Example output:

[ℹ]  eksctl version 0.70.0
[ℹ]  using region "<region>"
[ℹ]  deleting cluster "<cluster-name>"
[ℹ]  deleting stack "<cluster-name>"
...
[ℹ]  deleted EKS cluster "<cluster-name>" in "<region>"

Use case 6: Create cluster and write cluster credentials to a file other than the default

Code:

eksctl create cluster --name=name --nodes=4 --kubeconfig=path/to/config.yaml

Motivation:

This use case is useful when you want to create a cluster and store the Kubernetes configuration file in a custom location, rather than the default location (~/.kube/config).

Explanation:

  • eksctl create cluster is the command used to create a cluster.
  • The --name flag specifies the name of the cluster to be created.
  • The --nodes flag specifies the number of worker nodes to be included in the cluster.
  • The --kubeconfig flag specifies the path and filename to store the Kubernetes configuration file.

Example output:

[ℹ]  using region "<region>"
[ℹ]  creating cluster "<cluster-name>"
[ℹ]  created cluster "<cluster-name>", region="<region>"
[ℹ]  creating nodegroup "ng-<nodegroup-id>"
...
[ℹ]  node "ip-192-168-10-1.ec2.internal" is ready
[ℹ]  node "ip-192-168-20-1.ec2.internal" is ready
[ℹ]  saved kubeconfig as "<path/to/config.yaml>"

Use case 7: Create a cluster and prevent storing cluster credentials locally

Code:

eksctl create cluster --name=name --nodes=4 --write-kubeconfig=false

Motivation:

This use case is suitable when you want to create a cluster but do not want to store the cluster credentials locally.

Explanation:

  • eksctl create cluster is the command used to create a cluster.
  • The --name flag specifies the name of the cluster to be created.
  • The --nodes flag specifies the number of worker nodes to be included in the cluster.
  • The --write-kubeconfig=false flag instructs eksctl not to store the cluster credentials locally.

Example output:

[ℹ]  using region "<region>"
[ℹ]  creating cluster "<cluster-name>"
[ℹ]  created cluster "<cluster-name>", region="<region>"
[ℹ]  creating nodegroup "ng-<nodegroup-id>"
...
[ℹ]  node "ip-192-168-10-1.ec2.internal" is ready
[ℹ]  node "ip-192-168-20-1.ec2.internal" is ready

Use case 8: Create a cluster and let eksctl manage cluster credentials under the ~/.kube/eksctl/clusters directory

Code:

eksctl create cluster --name=name --nodes=4 --auto-kubeconfig

Motivation:

This use case is useful when you want eksctl to manage cluster credentials automatically and store them under the ~/.kube/eksctl/clusters directory.

Explanation:

  • eksctl create cluster is the command used to create a cluster.
  • The --name flag specifies the name of the cluster to be created.
  • The --nodes flag specifies the number of worker nodes to be included in the cluster.
  • The --auto-kubeconfig flag instructs eksctl to manage cluster credentials automatically and store them under the ~/.kube/eksctl/clusters directory.

Example output:

[ℹ]  using region "<region>"
[ℹ]  creating cluster "<cluster-name>"
[ℹ]  created cluster "<cluster-name>", region="<region>"
[ℹ]  creating nodegroup "ng-<nodegroup-id>"
...
[ℹ]  node "ip-192-168-10-1.ec2.internal" is ready
[ℹ]  node "ip-192-168-20-1.ec2.internal" is ready
[ℹ]  saved kubeconfig in "<~/.kube/eksctl/clusters/cluster-name.yaml>"

Conclusion:

The eksctl command-line tool provides a simple and efficient way to manage Amazon EKS clusters. It offers a variety of use cases to create, retrieve details, delete clusters, and control how cluster credentials are stored or managed. With the provided examples and explanations, users can effectively utilize eksctl to manage their EKS clusters on AWS.

Related Posts

How to use the command 'ansible-pull' (with examples)

How to use the command 'ansible-pull' (with examples)

Ansible is an open-source automation tool that allows you to manage and configure systems.

Read More
Applying Dithering to a Greyscale Image with `pamditherbw` (with examples)

Applying Dithering to a Greyscale Image with `pamditherbw` (with examples)

Dithering is a technique used to convert a greyscale image into a pattern of black and white pixels that closely resemble the original image.

Read More
How to use the command 'rip' (with examples)

How to use the command 'rip' (with examples)

Rip is a command-line tool that allows users to remove files or directories from specified locations and place them in a graveyard, where they can be recovered if needed.

Read More