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. 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. 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
Clusters
Task definitions
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.
Tasks
Services
Operating System and 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.
Pros 👍
The type of EC2 instance used here is entirely under your control.
You can use spot instances which reduce costs by up to 90%.
Cons 👎
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.
Pros 👍
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.
Cons 👎
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.
Pros 👍
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.
Cons 👎
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.
Pros 👍
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.
Cons 👎
It gives you less control in various ways
Conclusion
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.