top of page
Search

Connecting AWS EKS cluster to your mac

  • soubhik001
  • Feb 24, 2022
  • 2 min read

Updated: Aug 9, 2022


My goal was to create an EKS cluster in my AWS account and access it from my mac terminal as it is much easier to configure, build, deploy etc from the terminal. Though AWS has a very good and self explanatory documentation page, yet it took me some time to figure out the exact steps that needs to be followed to get this job done. Hence I list the steps below so that you can get everything required in one place. So just open your mac terminal and follow the below steps:


Before I even start with the steps, Step 0 would be to install homebrew in your mac if it is not installed yet. Trust me it makes your life lot easier for installing packages.


Run this command in your terminal :




if you want to learn more about homebrew go here: https://brew.sh/


1. Install eksctl - eksctl is a command line utility tool developed by weaveworks for creating and maintaining Kubernetes clusters on Amazon EKS.

  • Install the Weaveworks Homebrew tap.

brew tap weaveworks/tap
  • Install /Upgrade eksctl

brew install weaveworks/tap/eksctl
#in case already installed, upgrade with below command
brew upgrade eksctl && brew link --overwrite eksctl
  • Test installation

eksctl version

Source : https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html

2. Install Kubectl

  • Please note, the below command is to install version 1.21.2, please change your required version accordingly in the below command

  • Apply execute permissions

chmod +x ./kubectl
  • Copy the binary to a folder in your PATH

mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH

echo 'export PATH=$PATH:$HOME/bin' >> ~/.bash_profile
  • Verify installation

kubectl version --short --client

3. Install and test IAM Authenticator

brew install aws-iam-authenticator

aws-iam-authenticator help

Source : https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html


4. Install aws cli

  • Installation

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"

sudo installer -pkg ./AWSCLIV2.pkg -target /
  • Verfication

which aws
aws --version

Source : https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html


5. Configure aws cli with IAM UserID, Security, Zone and type.


Once AWS Cli is installed, you need to configure it so that it can connect to AWS. Use aws configure command to set the same. When you type aws configure and hit enter, you will be with the below which you need to fill in.


$ aws configure 
Access Key ID [None]: <Access Key Id> 
AWS Secret Access Key [None] : <Access Key> 
Default region name [None]: us-west-2 Default 
output format [None]: json

In case you do not have an Access Key ID and AWS Secret Access Key, you can create it from here : https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-creds-create


Please note, the AWS Secret Access Key is only visible while creating the key so make sure you save it some place secure.


6. You are done, to test your connection you can create a dummy cluster with the below command

eksctl create cluster --name test-cluster --region us-east-2 --nodegroup-name eks-nodes --node-type t2.micro --nodes 2

you can change the name, region, node-group and nodes as per your choice


7. Once the cluster is created, you can run Kubectl command to see if you can access the cluster.


kubectl get svc

If you get below error, you need to reconfigure your kubectl


The connection to the server localhost:8080 was refused - did you specify the right host or port?

Command to reconfigure kubectl :

 aws eks update-kubeconfig --name test-cluster --region us-east-2

You should be good to go now. Hope this helps!


 
 
 

Comments


bottom of page