Steps to Access EKS Cluster from Local Development Environment

Ramesh Babu Chayapathi
3 min readSep 5, 2024

--

To access an AWS EKS (Elastic Kubernetes Service) cluster from your local development environment, you need to set up several prerequisites and follow specific steps. Here’s a comprehensive guide to help you through the process:

Prerequisites

  1. AWS CLI: The AWS Command Line Interface (CLI) must be installed and configured on your local machine. This tool allows you to interact with AWS services from the command line.

Installation Instructions:

  • For macOS: Use Homebrew:
brew install awscli
  • For Windows: Use the MSI installer from the AWS CLI installation page.
  • For Linux: Use the package manager (like apt or yum) or download directly:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install

2. kubectl: The Kubernetes command-line tool kubectl is required to interact with your EKS cluster.

Installation Instructions:

  • Follow the official Kubernetes installation guide: Install and Set Up kubectl.

3. eksctl (Optional but Recommended): A simple CLI tool for creating and managing EKS clusters.

Installation Instructions:

  • For macOS:
brew tap weaveworks/tap brew install weaveworks/tap/eksctl
  • For Windows: Use the choco package manager:
choco install -y eksctl
  • For Linux:
curl --silent --location "https://github.com/weaveworks/eksctl/releases/download/latest_release/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp sudo mv /tmp/eksctl /usr/local/bin

4. AWS IAM Authenticator (If Needed): AWS IAM Authenticator is often included with kubectl in newer versions, but in some cases, you might need to install it separately.

Installation Instructions:

Step-by-Step Process

Configure AWS CLI:

If you haven’t already configured AWS CLI, you need to set up your credentials and default region. Run:

aws configure

You will be prompted to enter your AWS Access Key ID, Secret Access Key, default region, and default output format.

Obtain Cluster Credentials:

You need to update your local kubeconfig file with the credentials and context for your EKS cluster. Run:

aws eks --region <your-region> update-kubeconfig --name <your-cluster-name>

Replace <your-region> with your AWS region (e.g., us-west-2) and <your-cluster-name> with the name of your EKS cluster.

This command updates the ~/.kube/config file with the necessary authentication information for kubectl to communicate with the EKS cluster.

Verify the Configuration:

To confirm that kubectl is properly configured to interact with your EKS cluster, run:

kubectl get svc

This command will return a list of services running in the default namespace if everything is configured correctly.

(Optional) Use eksctl to Manage Cluster:

If you’re using eksctl to manage your EKS cluster, you can also use it to generate kubeconfig. Run:

eksctl utils write-kubeconfig --cluster=<your-cluster-name> --region=<your-region>

This command performs a similar function to the aws eks update-kubeconfig command.

Ensure IAM Permissions:

  1. Make sure that your AWS IAM user or role has the necessary permissions to interact with the EKS cluster. The user should have access to EKS, EC2, IAM, and CloudFormation services at a minimum.
  2. Attach the Amazon EKS Cluster Policy and Amazon EKS Service Policy to your IAM role or user.

Test Access to Your EKS Cluster:

Test the access by listing all the namespaces or pods in your cluster:

kubectl get namespaces kubectl get pods --all-namespaces

Troubleshooting Tips

  • Permissions: Ensure your AWS IAM role/user has the necessary permissions to access and manage the EKS cluster.
  • Network Configuration: Check VPC, subnet, and security group settings if you encounter connectivity issues.
  • kubectl Version: Ensure that your kubectl version is compatible with the EKS Kubernetes version.

Summary

By following these steps, you should be able to access your EKS cluster from your local development environment. This setup allows you to manage and interact with your Kubernetes resources efficiently.

--

--

No responses yet