Set up EKS cluster in AWS

Prasanna Nayak
4 min readJul 10, 2021

Different ways to setup EKS cluster:

  1. aws console
  2. ekcstl utility provided by aws
  3. IaC, Terraform

Prerequisties

  1. aws account with admin privilages
  2. aws cli access to use kubectl utility
  3. instance (to manage cluster by using kubectl)

Step by step procedure

  1. Create IAM role for EKS cluster.
  2. Create dedicated VPC for the EKS cluster.
  3. Create EKS cluster.
  4. Install & setup IAM authenticator and kubectl utility.
  5. Create IAM role for EKS Worker nodes.
  6. Create worker nodes.
  7. Deploying Demo application

1. Create IAM role for EKS cluster.

Go to IAM, create role, choose EKS, then EKS-Cluster case, add policy AmazonEKSClusterPolicy

2. Create dedicated VPC for the EKS cluster.

  • Go to CloudFormation service and click on create stack
  • specify the template details here. If you have your template in your s3 bucket you can specify the link or ypu can also upload the template file (According to your need)
  • In configure stack option you can configure your stack as per your requirement here i leave it as default.

After couple of minutes your stack will be ready to use.

You can see your custom vpc in vpc service.

3.Create EKS cluster.

Go to EKS cluster, click on create a cluster.

  • If you have multiple EKS role you have to select the right role otherwise it will automaticlly select the EKS role.
  • Now specify the dedicated vpc in next step, all the subnets associated to your vpc will automatically shown there.
  • Next, choose the right security group that is created by the stack.
  • In cluster endpoint access there are 3 options, Public, Private and public & private. Here i chose Private and Public. (choose accordingly to your requirement).
  • Next configure your logging according to your requirement.
  • Review your EKS then click on create
  • It will take some time to create.

Connect to your instance with awscli nstalled on it.

Type this command to view the iam users

aws iam list-users

4. Install & setup IAM authenticator and kubectl utility.

To install aws-iam-authenticator on Linux

Download the Amazon EKS vended aws-iam-authenticator binary from Amazon S3.

curl -o aws-iam-authenticator https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/aws-iam-authenticator

To install kubectl on Linux

Download the Amazon EKS vended kubectl binary for your cluster’s Kubernetes version from Amazon S3. To download the Arm version, change amd64 to arm64 before running the command.

  • Kubernetes 1.19:

curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/kubectl

Apply execute permissions to the binary.

chmod +x ./kubectl

Copy the binary to a folder in your PATH. If you have already installed a version of kubectl, then we recommend creating a $HOME/bin/kubectl and ensuring that $HOME/bin comes first in your $PATH.

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

After you install kubectl , you can verify its version with the following command:

kubectl version — short –client

Update kubectl into your profile.

kubectl get svc

aws eks –region [region-name] update kubeconfig –name [ClusterName]

to view nodes, type

kubectl get nodes

To view namespaces, type

kubectl get ns

5. Create IAM role for EKS Worker nodes.

  • Go to IAM, create role in EC2 service and assign the followinf roles:

AmazonEKS_CNI_Policy

AmazonWorkerNodePolicy

AmazonEC2ContainerReadOnly

  • Go to EKS service, click on compute tab and add node group
  • specify group name and then assign the IAM role.
  • In next step add security group.
  • Now set the compute configuration like AMI type. Instance type (based on your requirement)

Now go to EC2 and there based on your compute configuration, instances will be created.

Now go back to instance and type this command just to check status

kubectl get nodes –watch

6. Deploying Demo application

To deploy your application clone your repository.

Fetch your docker compose file and type the following command

kubectl apply -f [filename]

To view your service type

kubectl get svc

To check the pods type

kubectl get pods

  • your service will get a external link now type,

nslookup [external-link]

  • to access over application type,

curl [external-link]

  • paste the external link into your browser and you can view it

--

--