2021-05-26 18:25:06 +00:00
---
layout: docs
page_title: Architecture - AWS ECS
description: >-
Architecture of Consul Service Mesh on AWS ECS (Elastic Container Service).
---
# Architecture
2021-09-15 20:04:39 +00:00
The following diagram shows the main components of the Consul architecture when deployed to an ECS cluster:
2021-05-26 18:25:06 +00:00
2021-09-15 20:04:39 +00:00
![Consul on ECS Architecture](/img/consul-ecs-arch.png)
2021-05-26 18:25:06 +00:00
2021-09-15 20:04:39 +00:00
1. **Consul servers:** Production-ready Consul server cluster
2021-05-26 18:25:06 +00:00
1. **Application tasks:** Runs user application containers along with two helper containers:
2021-09-15 20:04:39 +00:00
1. **Consul client:** The Consul client container runs Consul. The Consul client communicates
2021-05-26 18:25:06 +00:00
with the Consul server and configures the Envoy proxy sidecar. This communication
is called _control plane_ communication.
2021-09-15 20:04:39 +00:00
1. **Sidecar proxy:** The sidecar proxy container runs [Envoy](https://envoyproxy.io/). All requests
2021-05-26 18:25:06 +00:00
to and from the application container(s) run through the sidecar proxy. This communication
is called _data plane_ communication.
2021-09-15 18:00:33 +00:00
1. **ACL Controller:** Automatically provisions Consul ACL tokens for Consul clients and service mesh services
in an ECS Cluster.
2021-05-26 18:25:06 +00:00
For more information about how Consul works in general, see Consul's [Architecture Overview](/docs/architecture).
2021-09-15 20:04:39 +00:00
In addition to the long-running Consul client and sidecar proxy containers, the `mesh-init` container runs
2021-09-15 18:00:33 +00:00
at startup and sets up initial configuration for Consul and Envoy.
2021-05-26 18:25:06 +00:00
### Task Startup
This diagram shows the timeline of a task starting up and all its containers:
![Task Startup Timeline](/img/ecs-task-startup.png)
2021-09-15 18:00:33 +00:00
- **T0:** ECS starts the task. The `consul-client` and `mesh-init` containers start:
- `consul-client` uses the `retry-join` option to join the Consul cluster
2021-05-26 18:25:06 +00:00
- `mesh-init` registers the service for this task and its sidecar proxy into Consul. It runs `consul connect envoy -bootstrap` to generate Envoy’ s bootstrap JSON file and write it to a shared volume. After registration and bootstrapping, `mesh-init` exits.
2021-09-15 18:00:33 +00:00
- **T1:** The `sidecar-proxy` container starts. It runs Envoy by executing `envoy -c <path-to-bootstrap-json>`.
2021-09-15 20:04:39 +00:00
- **T2:** The `sidecar-proxy` container is marked as healthy by ECS. It uses a health check that detects if its public listener port is open. At this time, your application containers are started since all Consul machinery is ready to service requests. The only running containers are `consul-client`, `sidecar-proxy`, and your application container(s).
2021-09-15 18:00:33 +00:00
### Automatic ACL Token Provisioning
Consul ACL tokens secure communication between agents and services.
The following containers in a task require an ACL token:
- `consul-client`: The Consul client uses a token to authorize itself with Consul servers.
All `consul-client` containers share the same token.
- `mesh-init`: The `mesh-init` container uses a token to register the service with Consul.
This token is unique for the Consul service, and is shared by instances of the service.
The ACL controller automatically creates ACL tokens for mesh-enabled tasks in an ECS cluster.
2021-09-15 21:18:37 +00:00
The `acl-controller` Terraform module creates the ACL controller task. The controller creates the
ACL token used by `consul-client` containers at startup and then watches for tasks in the cluster. It checks tags
2021-09-15 18:00:33 +00:00
to determine if the task is mesh-enabled. If so, it creates the service ACL token for the task, if the
token does not yet exist.
The ACL controller stores all ACL tokens in AWS Secrets Manager, and tasks are configured to pull these
tokens from AWS Secrets Manager when they start.