EKS vs. ECS vs. Fargate

SukYeon Jung
4 min readFeb 11, 2021

Choosing a container service based on cost

The use of containers has not only become popular but is now a norm. With the growing adoption of containers, managing them has become burdensome. For instance, when deploying and managing 100 containers on your infrastructure, having 50 of them crash and die would be problematic. Would you manually delete or fix each container in such a scenario? To address this issue, the concept of automatic container management, known as container orchestration, has emerged. Both cloud service providers and independent developers offer services for automation, including ECS/EKS (AWS), GKE (GCP), Docker Swarm (Docker), and more. This paper focuses on introducing the orchestration services (ECS and EKS) provided by AWS and how to choose between them based on costs.

What is ECS

ECS (Elastic Container Service) is a container orchestration service provided by AWS. This service effectively manages the lifecycle of containers. With ECS, you can start, load balance, stop, and terminate containers collectively, avoiding the need to handle each container individually. The ECS cluster is created first, and each container is placed within the cluster. The lifecycle of containers within a cluster is managed through a single control plane. The diagram below illustrates how ECS operates.

[Diagram1. ECS Structure]

To run containers, virtual machines are utilized, and there are two possible options: EC2 instances and Fargate. With the first option, EC2 instances are provisioned to host containers, and these instances are then connected to the ECS cluster, communicating with ECS through the ECS Agents installed on the EC2 instances. Using EC2 instances offers the advantage of manual instance configuration, which provides higher flexibility but can also become a burden due to the need for manual management.

The second option is to host containers on Fargate, a fully managed (serverless) service provided by AWS. Consequently, you don’t need to worry about infrastructure provisioning or configuration. Resources are automatically provisioned based on the required amount, scaling up and down as needed.

What is EKS

EKS is an alternative orchestration tool also provided by AWS. It leverages Kubernetes, an open-source project used for container management, as a service within the AWS ecosystem. There are several reasons why one might choose EKS over ECS. For instance, if you are already using Kubernetes clusters or prefer to be part of a larger Kubernetes community. However, EKS has one disadvantage — the need to pay for a control plane, despite providing more features. The diagram below demonstrates how EKS operates.

[Diagram2. EKS Structure]

In EKS, the master node, managed by AWS, takes care of the control plane. Similar to ECS, worker nodes host the containers on compute fleets (EC2 or Fargate), and the master node and worker nodes are connected via K8S worker processes. Three hosting options for containers are available: 1) self-managed, 2) semi-managed, and 3) fully-managed. Please refer to the table below for the infrastructure management levels of each service.

[Table 1. EKS Infra Management Level]

Pricing Scheme

The pricing for ECS involves the cost of EC2 instances. For EKS, it includes the cost of EC2 instances as well as an additional EKS Control Plane Cost (USD 73/month, AWS Seoul Region). Fargate pricing is calculated as follows: (0.04656 * Number of vCPU * Number of Hours Running) + (0.00511 * Memory Usage in GB * Number of Hours Running).

Calculations for EC2-based hosting and Fargate differ, and it may not be immediately clear which is more cost-effective. Let’s examine the examples below.

If you are running a single task on an m5.xlarge instance, the cost will be as follows. Fargate is the more affordable option.

[Table 2. Pricing tables: Assuming a container running on a m5.xlarge (4 vCPU, 16GB Memory) instance with on-demand pricing for 30 days(24 hours) fully in AWS Seoul Region as of 2021.02.03]

However, if you are running 20 tasks, and it is possible to put 5 tasks on a single EC2 instance, EC2 mode becomes cheaper.

[Table 3. Pricing Table: Assuming 20 tasks are run and 5 tasks can be run on a single EC2 instance]

Of course, this example assumes that you are running your application 24/7 and using on-demand instances only. If you can schedule the instances or if you use reserved instances or savings plans, the price can be significantly different. What this example shows is that before deciding between EC2 or Fargate for your hosting, you need to do calculations and make an informed choice. Generally, if you need high computing power and memory and require your application to run 24/7, EC2 emerges as the better choice. Serverless is not always the superior option, but it can be the better choice if it aligns with your business situation.

--

--

SukYeon Jung

Writes about cloud computing, company cultures, and finance