Amazon Elastic Kubernetes Service (EKS) is a managed service that simplifies running Kubernetes on AWS without installing or maintaining your control plane or nodes. In this guide, we’ll walk through setting up an EKS cluster and installing kubectl, the command-line tool that allows you to interact with your Kubernetes clusters.

Introduction to Amazon EKS

Amazon EKS is designed to provide a scalable and highly available Kubernetes environment in the cloud. It manages the Kubernetes control plane, including scaling, patching, and securing it. This allows you to focus on deploying and managing your applications rather than dealing with the complexity of Kubernetes infrastructure.

Understanding Amazon EKS and Its Uses

Amazon EKS is ideal for running containerized applications at scale. It’s beneficial for companies that want to leverage the power of Kubernetes but want to avoid managing the underlying infrastructure. EKS integrates seamlessly with other AWS services, making it an excellent choice for organizations already invested in the AWS ecosystem.

Creating an EKS Cluster

Setting up an EKS cluster involves several steps, starting with the initial configuration and ending with the final cluster creation. Here’s how to get started:

Initial Steps and Cluster Creation Process
  1. Access the EKS Console: Log into your AWS Management Console and navigate to the EKS section.
  2. Choose Cluster Creation Method: You can use the console wizard or command-line tools like eksctl or AWS CLI. This guide focuses on using the AWS Management Console for simplicity.
Choosing the Right Settings

When creating your EKS cluster, you’ll need to configure several settings:

  1. Cluster Name: Choose a unique and descriptive name for your cluster.
  2. Kubernetes Version: Select the version of Kubernetes you wish to run. AWS regularly updates EKS with new versions.
  3. Networking Options: Choose your VPC, subnets, and security groups. These settings determine how your cluster’s network is configured.
Finalizing Cluster Configuration
  1. Endpoint Access: Decide whether the cluster endpoint should be accessible publicly or privately.
  2. Logging: Enable or turn off logging for your cluster. Logs can be sent to AWS CloudWatch for monitoring and analysis.
  3. Review Settings: Before creating the cluster, review all the settings to ensure everything is configured correctly.

Setting Up AWS CloudShell

AWS CloudShell is a browser-based shell that provides a simple way to run AWS CLI commands and manage AWS resources. It’s an ideal environment for installing kubectl and managing your EKS cluster.

Enabling CloudShell and Preparing the Environment
  1. Access AWS CloudShell: In the AWS Management Console, open CloudShell by selecting the icon in the navigation bar.
  2. Prepare the Environment: Once CloudShell is open, ensure you have the IAM permissions to create and manage EKS clusters.
Installing kubectl on AWS CloudShell
  1. Download kubectl: Run the following command in CloudShell to download kubectl:
    curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/<kubectl-version>/2023-04-07/bin/linux/amd64/kubectl
  2. Make kubectl Executable: Modify the permissions to make kubectl executable:
    chmod +x ./kubectl
  3. Move kubectl to /usr/local/bin: Move kubectl to a directory that is in your PATH:
    sudo mv ./kubectl /usr/local/bin
Verifying kubectl Installation
  1. Check kubectl Version: Verify that kubectl is correctly installed by checking its version:
    kubectl version –short –client
  2. Ensure Correct Installation: The output should display the version of kubectl installed, confirming that the installation was successful.

Connecting to Your EKS Cluster

After setting up kubectl, the next step is to connect it to your newly created EKS cluster.

Generating kubeconfig and Testing Connectivity
  1. Generate kubeconfig: Use the AWS CLI to generate a kubeconfig file for your cluster:
    aws eks update-kubeconfig –region <region-code> –name <cluster-name>
  2. Test Connectivity: Run the following command to test the connection to your cluster:
    kubectl get svc

If everything is set up correctly, this command should return a list of services running in your cluster.

Cleaning Up AWS Resources

Once you’ve completed your EKS cluster, cleaning up resources is essential to avoid unnecessary costs.

Deleting the EKS Cluster and CloudShell Directory
  1. Delete the EKS Cluster: Go to the EKS console and delete your cluster. Alternatively, you can use the AWS CLI:
    aws eks delete-cluster –name <cluster-name>
  2. Clean Up CloudShell Directory: Remove any files or directories created during the setup process to keep your CloudShell environment clean.
    rm -rf <directory-name>

Following these steps, you can efficiently set up, manage, and clean up your Amazon EKS cluster using AWS CloudShell and kubectl.

References

Set up kubectl and eksctl

Get started with Amazon EKS