Mastering AWS EKS Commands (with examples)

Mastering AWS EKS Commands (with examples)

Amazon Elastic Kubernetes Service (EKS) provides a fully managed Kubernetes service, allowing users to run Kubernetes without needing to install and operate Kubernetes control plane or nodes within AWS. The AWS EKS command suite enables users to manage various aspects of EKS, including cluster creation, management, and node groups. These commands facilitate efficient Kubernetes operations on AWS, ensuring a seamless, scalable, and secure Kubernetes environment.

Use case 1: Create an EKS Cluster

Code:

aws eks create-cluster --name cluster_name --role-arn eks_service_role_arn --resources-vpc-config subnetIds={{subnet_ids}},securityGroupIds={{security_group_ids}}

Motivation:

Creating an EKS cluster is the foundational step for any Kubernetes deployment on AWS. It sets up the control plane, enabling you to orchestrate and manage containers across your entire infrastructure. This command is critical for launching applications and scaling workloads while leveraging AWS’s robust offerings.

Explanation:

  • --name cluster_name: Specifies a unique name for the EKS cluster, which helps identify and reference the cluster in subsequent commands.
  • --role-arn eks_service_role_arn: Provides the Amazon Resource Name (ARN) for the service role that the EKS cluster will assume. This role must have permissions to initiate AWS services on your behalf.
  • --resources-vpc-config subnetIds={{subnet_ids}},securityGroupIds={{security_group_ids}}: Defines the Virtual Private Cloud (VPC) configuration. The subnets and security groups must exist in your AWS account and allow the EKS control plane to connect to worker nodes.

Example Output:

{
    "cluster": {
        "name": "cluster_name",
        "arn": "arn:aws:eks:region:account-id:cluster/cluster_name",
        "createdAt": "datetime",
        "version": "1.18",
        "roleArn": "eks_service_role_arn"
    }
}

Use case 2: Update kubeconfig to connect to the EKS Cluster

Code:

aws eks update-kubeconfig --name {{cluster_name}}

Motivation:

Running this command is essential to configure your local Kubernetes client configuration (kubeconfig) with the new cluster’s details. This provides a seamless way to manage and operate the EKS cluster from your local development environment using tools like kubectl.

Explanation:

  • --name {{cluster_name}}: References the specific EKS cluster to generate the kubeconfig file. It ensures that cluster-specific connection details, certificates, and keys are accurately reflected in the local config file.

Example Output:

Updated context arn:aws:eks:region:account-id:cluster/cluster_name in /home/user/.kube/config

Use case 3: List available EKS clusters

Code:

aws eks list-clusters

Motivation:

Listing available EKS clusters is crucial for gaining a quick overview of all Kubernetes environments currently managed under your AWS account. This helps in managing multiple clusters and checking the status of your Kubernetes infrastructure.

Explanation:

This command requires no additional arguments and is straightforward to execute. It returns a list of all active cluster names, enabling easy navigation and further action on these clusters.

Example Output:

{
    "clusters": [
        "cluster_name1",
        "cluster_name2"
    ]
}

Use case 4: Describe EKS cluster details

Code:

aws eks describe-cluster --name {{cluster_name}}

Motivation:

Describing an EKS cluster is helpful for gaining detailed insights into the cluster’s configuration, such as status, VPC settings, and Kubernetes version. This information assists in cluster management and troubleshooting.

Explanation:

  • --name {{cluster_name}}: Identifies the specific EKS cluster to fetch descriptive information about. It allows you to examine and verify the cluster’s settings and current operational state.

Example Output:

{
    "cluster": {
        "name": "cluster_name",
        "status": "ACTIVE",
        "certificateAuthority": {
            "data": "base64-encoded-cert-data"
        },
        ...
    }
}

Use case 5: Delete an EKS Cluster

Code:

aws eks delete-cluster --name {{cluster_name}}

Motivation:

Deleting an EKS cluster is significant when you need to decommission or migrate environments, ensuring you manage your resources efficiently and eliminate unnecessary costs associated with unused infrastructure.

Explanation:

  • --name {{cluster_name}}: Specifies the EKS cluster to be removed. It is crucial to accurately identify the correct cluster to avoid accidental deletions.

Example Output:

{
    "cluster": {
        "name": "cluster_name",
        "status": "DELETING"
    }
}

Use case 6: List nodegroups in an EKS cluster

Code:

aws eks list-nodegroups --cluster-name {{cluster_name}}

Motivation:

Listing nodegroups within an EKS cluster helps manage the compute resources that run your workloads. It provides insights into how many and which nodegroups are available, aiding in resource allocation and cost management.

Explanation:

  • --cluster-name {{cluster_name}}: Indicates the EKS cluster from which to list all nodegroups. This information is vital for understanding the cluster’s compute layer.

Example Output:

{
    "nodegroups": [
        "nodegroup_name1",
        "nodegroup_name2"
    ]
}

Use case 7: Describe nodegroup details

Code:

aws eks describe-nodegroup --cluster-name {{cluster_name}} --nodegroup-name {{nodegroup_name}}

Motivation:

Understanding the specifics of a nodegroup within an EKS cluster allows for efficient resource management, troubleshooting, and optimization. This command provides detailed configurations, scaling settings, and operational status.

Explanation:

  • --cluster-name {{cluster_name}}: Identifies the EKS cluster that contains the nodegroup to be described.
  • --nodegroup-name {{nodegroup_name}}: Specifies the particular nodegroup of interest within the chosen cluster for which details are required.

Example Output:

{
    "nodegroup": {
        "nodegroupName": "nodegroup_name",
        "status": "ACTIVE",
        "scalingConfig": {
            "minSize": 2,
            "maxSize": 5,
            "desiredSize": 3
        },
        ...
    }
}

Conclusion:

The AWS EKS command suite is a powerful toolset for managing Kubernetes clusters on Amazon Web Services. By leveraging these commands, users can easily create, configure, update, and monitor their Kubernetes resources in a highly scalable and secure environment. These examples demonstrate the practical usage and benefits of the AWS EKS command suite, providing a fundamental basis for efficient Kubernetes operations in the cloud.

Related Posts

How to Use the Command 'autorandr' (with examples)

How to Use the Command 'autorandr' (with examples)

The ‘autorandr’ command is a versatile tool designed to automatically adjust your screen layout.

Read More
Utilizing the Command 'dep' for PHP Application Deployment (with Examples)

Utilizing the Command 'dep' for PHP Application Deployment (with Examples)

The dep command is a powerful tool for deploying PHP applications, specifically designed to streamline and automate the deployment process using Deployer.

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

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

The rawtoppm command is a powerful utility used in image processing to convert raw RGB streams into PPM (Portable Pixmap) images.

Read More