How to use AWS fargate with EKS

In this blog post, we cover the steps to set up an Amazon EKS cluster with a Fargate profile. We walk you through creating the EKS cluster, setting up the IAM role for Fargate, creating a Fargate profile, and launching pods on Fargate.

GraphQL has a role beyond API Query Language- being the backbone of application Integration
background Coditation

How to use AWS fargate with EKS

AWS (Amazon Web Services) offers two major solutions for container orchestration and deployment: Amazon Elastic Kubernetes Service (EKS) and AWS Fargate. In this blog, we’ll explore the differences and similarities between the two and help you determine which solution is best for your use case.

What is Amazon EKS?

Amazon EKS is a managed Kubernetes service that makes it easy to run Kubernetes on AWS. With EKS, you can deploy and manage containerized applications using Kubernetes, without having to worry about the underlying infrastructure. EKS automatically provisions and manages the control plane components, including the master nodes, and you only need to manage the worker nodes and the applications that run on them.

What is AWS Fargate?

AWS Fargate is a serverless compute engine for containers that runs containers natively on AWS without the need to manage the underlying EC2 instances. With Fargate, you simply specify the number of tasks and their resource requirements, and AWS takes care of the rest. Fargate handles the management and provisioning of the underlying infrastructure, freeing you up to focus on building and deploying your applications.

Similarities and Differences

One of the key similarities between EKS and Fargate is that both provide a managed solution for running containers on AWS. Both solutions also integrate with other AWS services, such as Amazon RDS and Amazon S3, making it easy to build, deploy, and run containerized applications.

One of the key differences between EKS and Fargate is the level of control you have over the underlying infrastructure. With EKS, you have the ability to configure the underlying EC2 instances and customize the Kubernetes control plane, while with Fargate, you simply specify the resource requirements for your tasks and AWS takes care of the rest.

Another difference between the two is the level of integration with Kubernetes. EKS is a fully managed Kubernetes service, so it provides a native Kubernetes experience, including all of the features and capabilities of Kubernetes. Fargate, on the other hand, is a container engine that runs containers natively on AWS, so it doesn’t provide the same level of integration with Kubernetes.

Which solution is right for you?

The choice between EKS and Fargate depends on your use case and specific requirements. If you’re already using Kubernetes and want to continue using it, EKS is the clear choice. It provides a native Kubernetes experience, complete with all of the features and capabilities of Kubernetes.

However, if you’re looking for a simpler solution that requires less management, or if you don’t have experience with Kubernetes, Fargate might be a better choice. With Fargate, you simply specify the resource requirements for your tasks, and AWS takes care of the rest.

In conclusion, both AWS EKS and Fargate offer powerful solutions for running containers on AWS, but the best solution for you will depend on your specific use case and requirements. Regardless of which solution you choose, you can be confident that you’re getting a managed, highly available, and scalable solution for running your containerized applications on AWS.

you can run Fargate tasks within an EKS cluster by using the Amazon EKS Fargate profile feature. The EKS Fargate profile allows you to run pods in your EKS cluster on the Fargate infrastructure. You can define a Fargate profile in your cluster to specify which pods run on Fargate and which run on EC2.

Setting Up an Amazon EKS Cluster with a Fargate Profile

Amazon Elastic Kubernetes Service (EKS) provides a managed Kubernetes service for deploying containerized applications. With the introduction of Fargate, you can now run Kubernetes pods directly on AWS Fargate without managing the underlying infrastructure. In this technical blog, we will guide you through the process of setting up an EKS cluster with a Fargate profile.

Prerequisites:

  1. An AWS account with appropriate permissions to create resources.
  2. AWS CLI installed and configured with your AWS credentials.
  3. Basic familiarity with Amazon EKS and Kubernetes concepts.

Step 1: Create an EKS Cluster:

1. Launch the AWS CLI and run the following command to create an EKS cluster:


aws eks create-cluster --name <cluster-name> --role-arn <eks-service-role-arn> --resources-vpc-config subnetIds=<subnet-ids>

Replace <cluster-name>with your desired cluster name, <eks-service-role-arn> with the ARN of the IAM role for EKS, and <subnet-ids> with your VPC’s subnet.

2. Wait for the cluster creation process to complete by monitoring the status with the aws eks describe-cluster command.

Step 2: Create an IAM Role for Fargate:

1. Create an IAM role specifically for Fargate by running the following command:


aws iam create-role --role-name <role-name> --assume-role-policy-document file://path/to/trust-policy.json

Replace <role-name> with a suitable name for the role, and provide the path to a JSON file containing the trust policy document.

2. Attach the required policies to the Fargate role. You can use the aws iam attach-role-policy command to attach policies such as AmazonEKSFargatePodExecutionRolePolicy.

Step 3: Create a Fargate Profile:

1. Create a Fargate profile for your EKS cluster using the following command:


aws eks create-fargate-profile --cluster-name <cluster-name> --fargate-profile-name <profile-name> --pod-execution-role-arn <fargate-execution-role-arn> --selectors namespace=<namespace>,<label-key>=<label-value>

Replace <cluster-name>with the name of your EKS cluster, <profile-name>with a desired name for the Fargate profile, <fargate-execution-role-arn>with the ARN of the Fargate execution role created in the previous step, and <namespace>, <label-key>, and <label-value>with the appropriate values for your pod selector.

2. Wait for the cluster creation process to complete by monitoring the status with the aws eks describe

Step 4: Launch Fargate Pods:

  1. Create a Kubernetes deployment or pod specification YAML file that defines your application’s pods.
  2. Apply the YAML file using kubectl apply -f <file-name>.yaml to launch your pods on Fargate.

Conclusion:

In this blog post, we covered the steps to set up an Amazon EKS cluster with a Fargate profile. We walked through creating the EKS cluster, setting up the IAM role for Fargate, creating a Fargate profile, and launching pods on Fargate. By leveraging EKS and Fargate, you can simplify the management of your Kubernetes infrastructure and focus more on deploying and scaling your applications.

Remember to clean up any unused resources after completing your experiments to avoid unnecessary costs.

I'm Jayesh Nage, an enthusiastic software engineer with a focus on Python Flask/Django Frameworks. In my free time, I enjoy watching films, playing chess and cricket, traveling, trekking, and learning new technologies.

Want to receive update about our upcoming podcast?

Thanks for joining our newsletter.
Oops! Something went wrong.