Getting Started with Kubernetes on AWS using EKS: A Complete Guide


Introduction
Kubernetes has become the de facto standard for container orchestration, but managing a Kubernetes cluster can be complex. Amazon Elastic Kubernetes Service (EKS) simplifies this by providing a managed control plane, automated scaling, and deep integration with AWS services.
What is Amazon EKS?
Amazon Elastic Kubernetes Service (EKS) is a managed Kubernetes service that makes it easy to run Kubernetes on AWS without needing to install and operate your own Kubernetes control plane. EKS is certified Kubernetes conformant, so existing applications running on upstream Kubernetes are compatible with EKS.
Prerequisites for EKS
Before diving into EKS, you should have:
Basic understanding of Kubernetes concepts
AWS account with appropriate permissions
AWS CLI installed and configured
kubectl
installedeksctl
(the EKS CLI tool) installed EKS
Lets go.
1, Create an IAM User with Admin Permissions
Navigate to IAM > Users and click on Add users and at the right top click on create user
Give your user a name and click next
Under the Permissions options select Attach policies directly, scroll down and select AdministratorAccess. click next and click on create User.
Select the newly created user and click on the security credentials tab.
Scroll down to Access keys and select Create access key
Select Command Line Interface (CLI)
And checkmark the acknowledgment at the bottom of the page, click on next and click on create access key.
You can choose to copy the access key and the secret access key separately and paste them into a local text file, or click Download .csv file.
Note: We will use the credentials when setting up the AWS CLI. Click Done.
2, Launch an EC2 Instance
On the search bar type EC2 and click on EC2 > Instances and Click Launch Instance
Give your instance a name and Leave t2.micro selected under Instance type. In the Key pair (login) box, select Create new key pair.
Give your Key pair a name and Click Create new key pair. This will automatically download the key pair for later use.
Scroll down to Network and click on Network settings Edit. leave all Network settings at default and on the Auto-assign Public IP: Select Enable and lunch your instance.
Click on the instance ID link (which looks like i-xxxxxxxxx), and give the new instance a few minutes to enter the running state. Once the instance is fully created.
click Connect at the top of the window.
In the Connect to your instance dialog, select EC2 Instance Connect scroll down and click Connect.
If the connection was successful it will show Amazon Linux 2023.
In the command line window, check the AWS CLI version using the command aws --version and enter
It showed an older version so we need to download the v2 version, to do this use the command: curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" and enter
After downloading we need to Unzip the file using the command: unzip awscliv2.zip and enter
To See where the current AWS CLI is installed type: which aws enter
It should be /usr/bin/aws.
Next step is to update it using the command: sudo ./aws/install --bin-dir /usr/bin --install-dir /usr/bin/aws-cli --update enter
To Check the version of AWS CLI use run same command: aws --version
To see the updated version.
Next step is to Configure the CLI with the command: aws configure
It shows AWS Access Key ID, remember the access key your copied or saved so copy paste in the access key ID and press enter
For AWS Secret Access Key, paste in the secret access key you copied earlier also.
For Default region name, enter your account location so i used us-east-1 during my documentation.
For Default output format, enter json.
To quickly confirm your exact location navigate to your EC2 instance Dashboard and confirm under your Zones.
Next step is to Download kubectl with the command: curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.16.8/2020-04-16/bin/linux/amd64/kubectl
Next step is to apply execute permissions to the binary with the command chmod +x ./kubectl and enter
After applying the execute permissions to the binary next is to Copy the binary to a directory in your path with this command mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
At this point ensure that kubectl is installed to do this run kubectl version --short --client
We have to Download eksctl after installing kubectl, to download eksctl run curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
we have to Move the extracted binary to /usr/bin after downloading with the command sudo mv /tmp/eksctl /usr/bin and enter
To Get the version of eksctl we download run eksctl version
see the options with the command line eksctl help
3, Provision an EKS Cluster [ creating an Eks Cluster ]
In this example, the --zones parameter was added using the us-east-1a,us-east-1b,us-east-1c,us-east-1d,us-east-1f AZs from the message above, all the zones within the us-east-1 were all added. Note l used us-east-1 for this example so your own locations might differs so endeavor to add all the related locations. use the command eksctl create cluster --name dev --region us-east-1 --zones us-east-1a,us-east-1b,us-east-1c,us-east-1d,us-east-1f --nodegroup-name standard-workers --node-type t3.medium --nodes 3 --nodes-min 1 --nodes-max 4 --managed
The creation will take 10-15 minutes to complete.
While waiting for the cluster creation navigate to Cloudformation and see the progress so far.
Select the eksctl-dev-cluster stack which is our control plane.
Click on Events to see all the resources that are being created, we will also see another new stack being created that’s our node group
Once both stacks are completed, navigate to Elastic Kubernetes service.
Note: if you see an issue stating your current user or role does not have access to kubernetes object on this Eks cluster, just ignore it cause is of no impact to the next steps of the activity. though during my example/practice i didn’t experience it, check the dev.
Click on the compute tab
Click the listed node group which is Standard-workers to see our kubernetes version, instance type, status.
Click the Networking tab to see our VPC subnets.
Navigate to Ec2 instance connect and close out of the existing CLI window and connect again in your instance dialogs select Ec2 instance connect and click connect.
in the new CLI check for our cluster with the command eksctl get cluster
Next is to enable it to connect to our cluster with the command aws eks update-kubeconfig --name dev --region us-east-1
4, At this pointwe need to Create a Deployment on our EKS Cluster.
first we need to install Git with the command sudo yum install -y git
Next is to download the course files so i had to clone this Git for the cause of our example/practical. to do that git clone https://github.com/ACloudGuru-Resources/Course_EKS-Basics
Next is to change directory using the command cd Course_EKS-Basics that’s to enter into the course eks-basics folder
At this point let have a look at our deployment files run cat nginx-deployment.yaml
To view our service file too run cat nginx-svc.yaml
Next is to create a service, to get thius done run kubectl apply -f ./nginx-svc.yaml
To check the status of our service run kubectl get service
Copy the external DNS hostname of the load balancer, and paste it into a text file, as we'll need it in a minute then go ahead and Create the deployment with the command kubectl apply -f ./nginx-deployment.yaml
Next is to check the status of our deployment with the command kubectl get deployment
At this point we need to view our pods run kubectl get pod to view it
Next is to view our ReplicaSets to do that i ran kubectl get rs
To also view our nodes i also ran kubectl get node
At this point we need to access the application using the load balancer, replacing <LOAD_BALANCER_DNS_HOSTNAME> with the IP you copied earlier (it might take a couple of minutes to update) to get this done use the command curl "<LOAD_BALANCER_DNS_HOSTNAME>"
5, Test the High Availability Features of Your EKS Cluster
To test the high availability features of our cluster first navigate to AWS console, on the EC2 instance select the worker node instance
NOTE i selected my control plane instead of worker node and that made my EKS instance not to state up a new instance. so to avoid such error endeavor to select the worker node.
click on the instance state
Select stop instance
After a few minutes a new Eks instance stated launching to keep our service running
At this point navigate back to our CLI to check the status of our nodes with the command kubectl get node
From what we have above it shows or displayed a NotReady so we have to check our pods with the command kubectl get pod
We'll see a few different statuses — Terminating, Running, or Pending — because, as the instances shut down, EKS is trying to restart the pods. so we have to Check the nodes again run kubectl get node
We should see a new node, which we can identify by its age. Wait a few minutes, and then check the nodes again
We have three in a Ready state. Check the pods again
We can see couple pods are now running as well. Check the service status with the command kubectl get service
Copy the external DNS Hostname listed in the output. so we can access the application using the load balancer by replacing <LOAD_BALANCER_DNS_HOSTNAME> with the DNS Hostname you just copied run curl "<LOAD_BALANCER_EXTERNAL_IP>"
We can see the Nginx web page HTML. but if you could not see yours wait amfew more minutes. In a new browser tab, gate to the same IP, where we should again see the Nginx web page as we did In the CLI.
Conclusion
Amazon EKS makes running Kubernetes easier, more secure, and cost-effective by offloading control plane management to AWS. Whether you’re deploying a small test app or a large-scale production workload, EKS provides the flexibility and reliability needed for modern cloud-native applications.
Subscribe to my newsletter
Read articles from Nweke Henry directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
