AWS EKS - Let's play with it
Tags: aws, eks, awsek
Published: 2023-06-14 21:03:08

Lets start talking about AWS EKS service, what it is, what it does and so on.

For this article, lets assume that you already have a basic knowledge about containers, basic knowledge about Kubernetes and how they work.

So, EKS states for Elastic Kubernetes Service and it is a managed service, that means you don't need to worry about infrastructure, where you can deploy your Kubernetes environment and without needing to install anything to have your control plane and nodes up and running. The only thing you need is a few clicks with the proper configuration.

The AWS EKS service is fully integrated with other AWS services like ECR that makes things easier to deploy your container images, load balancer to distribute the traffic to your pods, IAM to secure the environment among others.

We will not go deeper in theory about Kubernetes, so lets start having our hands dirty to better understand this service !

To interact with Kubernetes and our EKS service, we will need 2 tools that will help us. They are the eksctl (command line tool to interact with EKS service and use CloudFormation behind the scenes to create your cluster) and kubectl (to interact with Kubernetes services).

I'm using an EC2 instance with Amazon Linux 2023 as my environment, but you can choose any environment you feel comfortable. 

You can install eksctl issue the following commands:

```
ARCH=amd64
PLATFORM=$(uname -s)_$ARCH
curl -sLO "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$PLATFORM.tar.gz"
tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp && rm eksctl_$PLATFORM.tar.gz
sudo mv /tmp/eksctl /usr/local/bin
```
To make sure eksctl is installed successfully, issue the following command:

```
eksctl version
```
You should receive an output with the eksctl version like that:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25xgzrk59gwpbnbkyq01.PNG)
Now, lets install kubectl. To do that, just issue the following commands:

```
curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.27.1/2023-04-19/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
```
You can verify if the installation is fine with the following command:

```
kubectl version --short --client
```
It should return the kubectl version info like that:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2gquajfzb5gc4l11r1bt.PNG)

"Don't worry about the message saying that the flag --short has been deprecated."

Great, now we have everything we need to start working with our EKS service. The very first thing we need to start working is a cluster. When we create a cluster, we 2 node types that we can work with, they are:

- Fargate: this type of compute capacity is also know as serverless because you dont have EC2 instances to manage. You simply put your pods to run and nothing else.
- EC2 instances: this type uses EC2 instances to have your pods running, so you need to choose the instance family, instance size, number of instances and so on. In this case, the instances are customized for EKS service. 

So, let's create our cluster. To make things simple, lets use Fargate compute mode and default options. We can do that using the eksctl, issue the following command:

```
eksctl create cluster --name devto-article-eks-cluster \
--region us-east-1 \
--fargate
```
It will take a few minutes and when it finishes, you will see an output like that:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j88ml75r8ki7bjryz2un.PNG)

Now that our cluster is live, we can try some kubectl commands to interact with. Lets try a command to list the nodes, so just type:

```
kubectl get nodes -o wide
```
The output will list the nodes like that:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a43z76i9pkhr5fp7t8mo.PNG)

When you create a Kubernetes cluster, it created some internal pods that are used by Kubernetes to work properly. What about to see what are those services ? To do that, issue the following command:

```
kubectl get pods -A -o wide
```
The output should like following:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vk4b1ffw7uy4147c931c.PNG)

Those are coredns pods, that act as a DNS server for Kuberntes pods. We will not go deeper in Kubernetes sctructure, so that information is enought for now. Lets keep focusing on EKS service.

Great, now we can create our Kubernetes deployment that will pull our container image from a repository. We can run our pod with the following command:

```
kubectl run devto-article-pod --image <your_account_id>.dkr.ecr.us-east-1.amazonaws.com/my-eks-container-repo:latest
```
"Remember to replace the subnet ids by your subnets".

Lets check if out pod is running as expected. Type the following command:

```
kubectl get po
```
The output shows our container running in a pod as expected:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7iqulvk5lwn4iczlspi0.PNG)
Now, the final part, make sure our pod has a container doing what is expected, show the welcome message ! Lets check that, we just need to login into the container which is running our app and execute a curl to check the message. Go ahead and execute the following commands:

```
kubectl exec -it devto-article-pod -- /bin/bash
```
Amaaaaazing news !!! Our pod is running the container as expected:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzmq2mhn9839hfqgo54y.PNG)
After some commands, we are finally done with our mission to have a pod application running on a EKS cluster as required. 

You did a great job. Thank you so much for follow me in this article and see you in the next.

sources:

https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html
https://eksctl.io/usage/creating-and-managing-clusters/
https://docs.aws.amazon.com/eks/latest/userguide/sample-deployment.html
https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html