- Create a EFS drive.
- Attach a security group to EFS
- Create an ECS cluster
- Generate an AWS ECS task role with the following permissions. You will use this role for the Traefik task created later:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "TraefikECSReadAccess",
"Effect": "Allow",
"Action": [
"ecs:ListClusters",
"ecs:DescribeClusters",
"ecs:ListTasks",
"ecs:DescribeTasks",
"ecs:DescribeContainerInstances",
"ecs:DescribeTaskDefinition",
"ec2:DescribeInstances"
],
"Resource": [
"*"
]
}
]
}
- Create a launch configuration from the latest ECS AMI. Should have the following snippet as user data.
- should be replaced by the ECS Cluster name from the cluster created in step 3.
- should be replaced by the first part of the EFS DNS name from the file system created in step 1.
#!/bin/bash
echo ECS_CLUSTER=<ECS-CLUSER-NAME> >> /etc/ecs/ecs.config
yum install -y nfs-utils
mkdir /efs
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 <EFS-URL>.amazonaws.com:/ /efs
service docker restart
start ecs
-
Ensure the instance has an IAM role with the AmazonEC2ContainerServiceforEC2Role policy
-
Create an auto scaling group - peg the number of instances for now (no scaling)
-
Create a new ECS task for traefik
- Use dben0/traefik-ecs for the latest version of this repository
- Or, to build your own version, run
chmod 555 docker-entrypoint.sh
to ensure permissions are correct, and then build and push to your own repository - Set a soft limit on the memory od between 100-500MB
- Pass through ports 80, 8080, and 443
- Set the command to some variation of:
--api,--ping,--ping.entrypoint=http, --loglevel=DEBUG
--api: enables traefik management api
--ping: sets up a /ping endpoint on containers to use for health checks
--ping.entrypoint: choose between http and https for the ping endpoint
--loglevel: sets log level
- mount the volume /efs/acme.json to /acme.json
- set the environment variables
AWS_ACCESS_KEY_ID <AWS-ACCESS-KEY> AWS_REGION <AWS-REGION (us-east-1)> AWS_SECRET_ACCESS_KEY <AWS-SECRET> CLUSTER_HOST <ECS-CLUSER-NAME> DOMAIN TLD to use by default ENVIRONMENT default subdomain name EMAIL letsencrypt email address
- set the labels on your container (feel free to go wild!) https://github.com/containous/traefik/blob/master/docs/configuration/backends/docker.md#on-containers
traefik.frontend.rule Host:<YOUR.TRAEFIK.URL> (optional) traefik.enable true traefik.port 8080 (lock this port behind a firewall)
- remove the host port on your container, and launch it in a service. Traefik will scale across containers on any instance.
- Add the following labels to your application task:
traefik.frontend.rule Host:<YOUR.DOMAIN.NAME> (optional)
traefik.enable true
traefik.backend <UNIQUE-NAME> (optional, shows in the admin)
traefik.frontend.redirect.entryPoint https (optional)
traefik.frontend.redirect.permanent true (optional)
- Update route 53 to round robin all autoscaling containers
- Future task: lambda to update route 53 when autoscaling occurs. https://gist.github.com/ambakshi/8d2276af73cc896cab5f