AWS Fargate is a technology that can be used with Amazon ECS and Amazon EKS. It allows you to run containers without managing servers or clusters of Amazon EC2 instances.
Fargate eliminates the need to configure, scale, or provision virtual machine clusters to execute containers. There will be no need to select server kinds, schedule cluster scaling, or optimize cluster packing.
We can use the Fargate launch type or a Fargate capacity provider to run your Amazon ECS tasks and services. To use Fargate, you can package your application in containers, specify the Operating System, CPU, and memory requirements, configure networking and IAM policies, and launch it.
There is no need to maintain a base CPU and RAM capacity to host containers. We can tell AWS how much resource a task needs and leave the rest of the task to AWS. Each Fargate task has its isolation barrier, so it doesn’t share the underlying kernel, CPU, memory, or elastic network interface with other tasks.
How Does Fargate Work?
Fargate works by allowing you to deploy containers without setting up or managing the infrastructure that will host them. You tell Fargate which container images you want to run and how many CPU and memory resources you wish to assign. The host servers are then automatically provisioned by Fargate. When your containers are running, you only pay for the resources used.
Fargate is a serverless computing engine, as it eliminates the need for end-users to manage the servers that host containers. To be clear, the servers are still there; AWS simply manages them. Fargate is not to be confused with AWS Lambda, another serverless computing service that was not created with containers in mind (although Lamba now supports the deployment of container images).
How does Fargate help?
AWS Fargate calculates the exact amount of computing, memory, and other resources required for your tasks, so you don’t have to worry about choosing instance kinds or scaling the cluster capacity.
It allows you to pay for the resources you need to operate your containers as they are used, avoiding overprovisioning and paying for servers you don’t need.
Fargate tasks (pods) execute in their own kernels, resulting in a safe and isolated compute environment with isolated workloads and increased security.
It enables teams to design and run apps using ECS or EKS containers without having to deal with time-consuming infrastructure management activities such as scaling and securing servers or patching operating systems.
With built-in connections with other AWS services like Amazon CloudWatch Container Insights, AWS Fargate delivers a high level of observability. You can also use Multiple third-party technologies to collect logs and metrics.
We can also efficiently utilize the vast array of AWS services when using containers with Fargate.
Fargate will constantly launch and scale computing resources to fit the container’s requirements, preventing over-provisioning and ensuring you don’t pay for resources you don’t use. You can also calculate a savings strategy, the Fargate Spot option can save you up to 70% off ordinary costs, but it’s only optimal for interruptible applications.
Components of Fargate
A logical grouping of tasks or services is an Amazon ECS cluster. Clusters can be used to isolate your applications. When you use Fargate to conduct your tasks, it manages your cluster resources.
A task definition is a text file that describes at least one of your application’s containers. It’s a JSON file. It can be used to describe up to ten containers at a time. Your application’s task definition serves as a blueprint. It specifies your application’s numerous parameters.
For example, you can use it to define operating system parameters, containers to use, ports to open for your application, and data volumes to use with the containers in the task. The requirements of your application determine the particular parameters available for task definition.
A task is a cluster-level instantiation of a task definition. Once you’ve created a task definition for your application in Amazon ECS, you can choose the number of tasks that will run on your cluster. We can run a task as part of a service or a separate process.
In an Amazon ECS cluster, you can utilize an Amazon ECS service to run and maintain your desired number of tasks simultaneously. The Amazon ECS service scheduler runs another instance based on your task definition if any of your tasks fail or halt for whatever reason. It does this to replace it and keep the number of tasks in the service at the correct level.
Operating System and CPU architecture
The operating systems supported by Fargate are Amazon Linux 2, Windows server 2019 Full, and Windows server 2019 core.
ARM and X86_64 are the two architectures available for Amazon ECS task definition. If you use Windows containers, you must have an X86_64 CPU architecture. In contrast, if you use Linux containers, you can use the ARM64 architecture for your ARM-based applications and the X86_64 CPU architecture.
ECS with EC2 instances Vs. ECS with AWS Fargate
In the EC2 instance model, containers are deployed to the cluster’s EC2 instances (VMs). ECS manages them in conjunction with tasks that are part of the task definition.
- The type of EC2 instance used here is entirely under your control.
- You can use spot instances which reduce costs by up to 90%.
- You have to take care of security patches and network security of the instances; also, you are responsible for their scalability in the cluster.
In the Fargate model, you no longer need to be concerned about EC2 instances or servers. Select the CPU and memory configuration required, and Fargate will deploy your containers.
- You don’t have to manage any servers.
- AWS is responsible for availability and scalability, but it is still a good practice to select the correct memory and CPU; otherwise, our application might be at risk of becoming unavailable.
- If you decide to use Fargate Spot, you can get up to a 70% discount on the Fargate price.
- ECS with AWS Fargate supports only one networking mode -awsvpc-. As a result, this limits your control over the networking layer.
EKS without Fargate Vs. EKS with Fargate
In EKS without the Fargate model, you must decide how large the cluster should be ahead of time. You can always change the nodes manually later, but it is troublesome compared to specifying the ideal size from the start.
- This model gives you more control in various ways like you can specify configuration variables like HostNetwork and HostPort.
- Fargate is not supported in all the regions, so you prefer to use EKS without Fargate if you want your container to be available in more regions.
- EKS without Fargate is a bit hard to use.
In EKS with the Fargate model, you don’t have to specify the size of clusters beforehand.
- EKS with Fargate is more secure because they run inside dedicated virtual machines. The fact that it doesn’t support privileged mode is kind of a security feature.
- It is cheaper in the long run.
- It gives you less control in various ways
Fargate is an extremely powerful and mature tool. It saves you cost, time, and a lot of effort by doing all the infrastructure management for you. Fargate is especially beneficial if you are new to containers and simply want to focus on building your application rather than maintaining it.