EKS: Guide to create Kubernetes clusters in AWS
Tags: aws, kubernetes, devops, tutorial
Published: 2023-07-13 15:19:00

Amazon Elastic Kubernetes Service (EKS) is a managed service within AWS, that allows you to run a Kubernetes cluster. Managed service translates into the fact that there's no need to install, or maintain the cluster's control or data plane.

**Prerequisites**

You're going you need a user with the right policies for services like EKS, CloudFormation, EC2, IAM, and an access key for that user ([guide here](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey)).

**Tooling**

- `kubectl` - CLI for communicating with Kubernetes ([installation guide here](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/))
- `aws` - CLI for interacting with AWS services ([installation guide here](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html))
- `eksctl` - CLI for creating and managing clusters on EKS ([installation guide here](https://eksctl.io/introduction/#for-unix))

**Configuration**

`aws iam` authenticator that allows you to use AWS IAM credentials to authenticate ([installation guide here](https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html))

[Configure AWS CLI](https://docs.aws.amazon.com/cli/latest/reference/configure/index.html): run the following command without arguments in order to get prompted for configuration values (e.g. AWS Access Key Id and your AWS Secret Access Key, AWS region).

```bash
aws configure
```
[IAM AWS CLI](https://docs.aws.amazon.com/cli/latest/reference/iam/index.html): for `eksctl` you will need to have AWS API credentials configured. Amazon EKS uses the IAM service to provide authentication to your Kubernetes cluster through the [AWS IAM authenticator for Kubernetes](AWS IAM authenticator for Kubernetes.).

Next you can verify if you're authenticated by running the following command:
```bash
aws iam get-user
```

**Creating Kubernetes cluster**

First you can list if there are any existing clusters (normally you should not have them if this is a fresh setup).
```bash
eksctl get clusters
```

To allow SSH access to nodes, `eksctl` imports by default the ssh public key from `~/.ssh/id_rsa.pub` , but if you want you can use another SSH public key by passing the absolute path to the key to `--ssh-public-key` flag.

[EKS clusters](https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html) run in a VPC, therefore you need an [Amazon VPC](https://docs.aws.amazon.com/eks/latest/userguide/network_reqs.html) with public and private subnets. The VPC must have a sufficient number of IP addresses available for the cluster, any nodes, and other Kubernetes resources that you want to create, and also it must have DNS hostname and DNS resolution support (otherwise nodes can't register to the cluster). You can't change which subnets you want to use after cluster creation.

The beauty of it, is that `eksctl` will do all the heavy lifting for you, and even more it allows to [customize your Kubernetes cluster](https://eksctl.io/introduction/) as needed (number of nodes, region, size of the nodes).

Example for 2 cluster node in the eu-west-1 region:
```bash
eksctl create cluster --name=demo_cluster --nodes=2 --region=eu-west-1 --ssh-public-key=eks_key.pub
```

Behind the scenes `eksctl` uses CloudFormation, you can see that in this case, it creates 2 CloudFormation stacks, one for cluster itself (control plane) and one for the initial managed nodegroup (woker nodes).

Furthermore you can use [CloudFormation console](https://console.aws.amazon.com/cloudformation/home) to check the status of it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8npys8k9oxkzf5o9bg6i.png)

After the cluster was created everything is set, you can verify that `kubectl` point to the correct cluster by running:
```bash
kubectl config current-context
```

Leveraging `eksctl` you can deploy a Kubernetes cluster in AWS in a matter of minutes.

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