As many people these days at foodpanda we are also moving towards microservices approach using docker containers. Docker allows to run applications in an isolated way, wherever you need. However, running many of them is hard to scale and deploy. Did you already hear about Elastic Container Service (ECS) by Amazon Web Services ? after reading this article you should have basic knowledge about what this service can offer to you. Last but not least, I am also comparing it with kubernetes.
Microservice is for some time already, one of these cool words any IT developer wants to hear in a conference or in a job interview. Microservices wouldn’t be the same without docker and also docker wouldn’t be the same without a tool to manage its containers. Some of these container tools are kubernetes and ECS by AWS.
At foodpanda, ECS was a product which became more interesting when the new application Load Balancer (ELB) was released. This new ELB allows to route traffic on dynamic ports inside EC2 instances. In the past, the classic load balancer was only able to route traffic to the same port on all the instances of the Auto Scaling Group (ASG).
So, “what has to do with ECS?” This new load balancer is able to route traffic to different ports exposed by multiple containers running for same service inside an instance. This Application Load Balancer not only reduces the chances of wasting resources but also increases the speed of scaling up your application (if no boot time required).
The following picture shows now how multiple containers for same purpose (service) can be running and scaled inside same ec2 instance.
In a nutshell these are the components of ECS:
- ECS agent:
- Daemon by amazon used for connecting instances to a cluster.
- If installed, ec2 automatically is attached to default cluster.
- Task Definition:
- Describes the container(s), volume(s)… of an ECS Service. Task definitions have revisions.
- A Task definition should group containers which share common purpose.
- Task definitions can only have up to 10 container definitions.
- Used for configuring the amount of tasks definitions desired to be running.
- Defines the scaling and deployment rules for the tasks definitions.
- Used by the ECS Scheduler in order to have the amount of healthy task definitions running.
- Service Scheduler:
- Internal service by amazon (hidden for aws users or apis) for managing the cluster.
- It simply holds the elements above.
- Clusters can contain multiple different container instance types.
- Clusters are region-specific.
- Container instances can only be a part of one cluster at a time.
ECS is fully supported by both api and cli so you can easily integrate the deployment of new task definitions (container images) inside your CI tool.
Don’t worry if by mistake you deploy a broken release, ECS scheduler uses the ELB health check in order to evaluate whether the task definition you are trying to deploy is healthy enough or not. In case it fails, ECS schedulers stops the deployment.
ECS scheduler only scales the amount of task definitions, so it only starts/stops containers from a limited amount of instances running on your Auto Scaling Group (ASG). This means that you still have to configure instance scaling policies for that ASG. Luckily you can use ECS metrics such as “reserved_memory” or “reserved_cpu” in order to increase/reduce number of instances available in the cluster. On the other hand, ECS scheduler can scale not only based on classic metrics such as CPU consumed by your containers but also based on custom metrics such as messages available from a sqs queue.
ECS compared by Kubernetes (K8s) v1.4.6 (latest stable release)
The following table shows what ECS can and cannot do compared by another cluster manager called kubernetes. Notice that it does not try to show what both can do:
|Custom metric service scaling (containers)||✔|
|Instance (server) scaling based on cluster metrics||✔|
|Requires extra instance for cluster management||✔|
|Can run on dev env||✔|
|Requires extra host for Service Load Balancer||✔|
To me, both have its pros and cons so it is up to project requirements which one to use. However, if your infra is really tied to aws services, ECS is probably the best option since you might run yourself the missing services.