DEV Community

Victor Gomez
Victor Gomez

Posted on

Mastering eksctl Commands: A Comprehensive Guide

Image description

eksctl is an incredibly powerful tool for managing Amazon EKS clusters, and it quickly became our goto solution for automating Kubernetes deployments. With its extensive set of commands, we were able to streamline our workflow, reduce errors, and increase productivity. But, as with any new tool, there was a learning curve.

In this tutorial, I will share the essential eksctl commands that every DevOps engineer should know. These commands are essential for managing Kubernetes clusters, deploying applications, and troubleshooting issues. By mastering these commands, you can take your container orchestration skills to the next level and become a certified eksctl expert.

Before we dive into the specific commands, let me provide some context on why they are important. Kubernetes is an opensource platform for automating deployment, scaling, and management of containerized applications. Amazon EKS is a managed Kubernetes service that makes it easy to deploy and manage Kubernetes clusters in the cloud. eksctl is a tool for managing Amazon EKS clusters, and it provides a set of commands for interacting with these clusters.

Now, let’s get started with the essential eksctl commands:

If you have more than one profile, you will need to specify the name of your profile using the --profile subparameter.

eksctl create: This command creates a new Amazon EKS cluster. It takes several parameters, such as the cluster name, the number of nodes, and the instance type.

eksctl create name mycluster nodes instancetype m.large
Enter fullscreen mode Exit fullscreen mode

​ But the easiest way to deploy is to define everything in a YAML file! You can run something like this:

eksctl create cluster -f k8s.yml --profile dynacode_profile
Enter fullscreen mode Exit fullscreen mode

Sure thing, you need to create a YAML file before you run this command. For example:

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: basic-cluster001
  region: us-east-1

nodeGroups:
  - name: ng-1
    instanceType: m5.large
    desiredCapacity: 10
  - name: ng-2
    instanceType: m5.xlarge
    desiredCapacity: 2


Enter fullscreen mode Exit fullscreen mode

If you want to download this small yaml, you can do so from our GitHub repository.

apiVersion:
This line specifies the eksctl API version that this configuration file uses. In this case, it's eksctl.io/v1alpha5, which corresponds to eksctl API version 1 alpha 5.

kind: ClusterConfig
This line defines the type of configuration object being described. Here, it specifies that this is a ClusterConfig object, which contains the details for creating a Kubernetes cluster.

metadata:
This section provides metadata about the cluster being created.

name:
Specify the name you want to give your EKS cluster. In this case, it is set to basic-cluster.

region:
Specify the AWS region where you want to create your cluster. In this case, it is set to us-east-1.

nodeGroups:
This section defines the different worker node groups that will be created for your cluster.

name:
Define the name of the node group. The configuration has two groups called ng-1 y ng-2.

instanceType:

Pick the Amazon EC2 instance type you want to use for the nodes in this group. In this case, "ng-1" uses m5.large instances and "ng-2" uses m5.xlarge instances. These instance types offer different levels of processing power and memory.

desiredCapacity:
Set the number of nodes you want in this group. The configuration sets "ng-1" to have 10 nodes and "ng-2" to have 2.

This YAML file sets up a Kubernetes cluster called "basic-cluster" in the eu-north-1 region of Amazon EKS. It creates two node groups: "ng-1" with 10 m5.large instances and "ng-2" with 2 m5.xlarge instances. You can use this configuration with the eksctl create cluster command to provision the cluster in AWS.

eksctl update This command updates the configuration of an existing Amazon EKS cluster. It takes the same parameters as eksctl create, such as the cluster name and the instance type.

    eksctl update name mycluster nodes  instancetype m.xlarge
Enter fullscreen mode Exit fullscreen mode

eksctl delete This command deletes an Amazon EKS cluster. It takes the cluster name as a parameter.

eksctl delete cluster basic-cluster001 --profile dcode_profile --region us-east-1
Enter fullscreen mode Exit fullscreen mode

eksctl get This command returns information about an Amazon EKS cluster, such as its ID, node count, and instance type. It takes the cluster name as a parameter.

eksctl get name mycluster
Enter fullscreen mode Exit fullscreen mode

eksctl listnodes This command lists all the nodes in an Amazon EKS cluster. It takes no parameters.

eksctl listnodes name mycluster
Enter fullscreen mode Exit fullscreen mode

eksctl logs This command displays the log output of a container running on an Amazon EKS node. It takes the name of the container as a parameter, followed by the node name.

eksctl logs container mycontainer node mynode
Enter fullscreen mode Exit fullscreen mode

eksctl scale: This command scales the number of nodes in an Amazon EKS cluster up or down. It takes the cluster name and the desired number of nodes as parameters.

eksctl scale name mycluster nodes
Enter fullscreen mode Exit fullscreen mode

eksctl tag: This command adds a tag to an Amazon EKS cluster. It takes the cluster name, the tag key, and the tag value as parameters.

eksctl tag name mycluster key 'owner' value 'dynacode'
Enter fullscreen mode Exit fullscreen mode

eksctl untag This command removes a tag from an Amazon EKS cluster. It takes the cluster name and the tag key as parameters. For example: eksctl untag name mycluster key “owner”

eksctl rollback This command restores an Amazon EKS cluster to a previous state. It takes the cluster name and the desired revision as parameters. For example: eksctl rollback name mycluster revision d

eksctl commands is essential for any DevOps engineer working with Kubernetes clusters in the cloud. By understanding these commands and how to use them effectively, you can streamline your workflow, reduce errors, and increase productivity. Remember, practice makes perfect, so keep experimenting with these commands to become a certified eksctl expert.

Hey there, don't forget to show some love on our Patreon!

If you found this post helpful, please consider supporting us on Patreon. We also have a website where we dive into all things Python and DevOps/DevSecOps.

Your support means the world to us, so thank you for being a part of our community!

Top comments (0)