Skip to main content

Creating an Amazon EKS Cluster

Objective

Creating an Amazon EKS cluster with eksctl allows for a wide range of configurations to cater to different needs. This can be achieved directly via command-line parameters or, for more complex setups, by utilizing a configuration file. This lab shows you how to create an Amazon EKS cluster using a configuration file specifically aimed at deploying the python-fastapi-demo-docker project's resources.

Initial Setup

Navigate to the root directory of the python-fastapi-demo-docker project where your environment variables are sourced:

cd ~/environment/python-fastapi-demo-docker

1. Using the cluster configuration file for Fargate nodes

The create-fargate-python.yaml eksctl configuration file sets up a Fargate-based cluster for deploying our python-fastapi-demo-docker with the following components:

  • Metadata: This section contains crucial metadata about your cluster, such as the cluster's name ("fargate-quickstart"), the AWS region where the cluster will be hosted ("us-east-1"), and the Kubernetes version ("1.26") that the cluster will run.
  • Fargate Profiles: This section configures the Fargate profiles, which determine how and which pods are launched on Fargate. By default, a maximum of five namespaces can be included. In our configuration, we're using the default and kube-system namespaces and have also added a custom namespace, my-cool-app, to host the application we plan to deploy on the cluster.
  • Permissions (IAM): This section outlines how the configuration utilizes IAM roles for service accounts through an OpenID Connect (OIDC) identity provider. Two service accounts are established here: aws-load-balancer-controller, which authorizes Kubernetes to manage the AWS Load Balancer Controller (LBC), ecr-access-service-account, which facilitates interactions with the Amazon Elastic Container Registry (ECR).
  • Logs (CloudWatch): The configuration wraps up with a cloudWatch section, which sets up Amazon CloudWatch logging for the cluster. All categories of Kubernetes control plane logs are enabled and are set to be retained for 30 days.

2. Creating the Cluster

From the python-fastapi-demo-docker project directory, create the cluster using the eksctl configuration file:

caution

Make sure to verify the region specified in eks/create-fargate-python.yaml and change it, if needed. The region must be same as the one you used in your .env file.

eksctl create cluster -f eks/create-fargate-python.yaml
tip
  • To avoid execution errors, update eksctl to the latest version using eksctl official documentation.
  • If you receive an Error: checking AWS STS access in the response, be sure to check that you’re using the right IAM user identity for the current shell session. Depending on how you configured the AWS CLI, you may also need to specify a named profile (for example, --profile clusteradmin).

Upon completion, the output should look something like this:

2023-05-26 13:10:23 [✔]  EKS cluster "fargate-quickstart" in "us-east-1" region is ready

3. View Namespaces

Check the namespaces in your cluster by running the following command:

kubectl get namespaces

The output should look something like this:

NAME              STATUS   AGE
default Active 27m
kube-node-lease Active 27m
kube-public Active 27m
kube-system Active 27m
my-cool-app Active 27m
tip
  • If you receive authentication errors, update kubeconfig using the following command aws eks update-kubeconfig --name fargate-quickstart

4. Creating a Namespace

While we've already created the necessary Fargate profile and namespace for this workshop, to create any additional namespace and fargate profile, run the following commands:

kubectl create namespace my-cool-app-v2

Before creating a Fargate Profile, first ensure that Fargate PodExecutionRole exists in the account. Create a PodExecutionRole with name AmazonEKSFargatePodExecutionRole if it doesn't exist following the steps in EKS Fargate documentation.

Then create a Fargate profile running the command below:

aws eks create-fargate-profile \
--region ${AWS_REGION} \
--cluster fargate-quickstart \
--fargate-profile-name fp-dev \
--pod-execution-role-arn arn:aws:iam::${AWS_ACCOUNT_ID}:role/AmazonEKSFargatePodExecutionRole \
--selectors namespace=my-cool-app-v2

Conclusion

This lab has walked you through the process of creating an Amazon EKS Fargate cluster pre-configured to deploy the python-fastapi-demo-docker project's resources. By following these instructions, you've set up a functioning Kubernetes cluster on Amazon EKS, ready for deploying applications.