Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register EC2 instance to ECS cluster without public ip

I'm having hard times adding instances that are created in my VPC and on a private subnet(no internet gateway attached to it) to ECS cluster.

Right now the only way I've managed to do this was by adding a public IP and have a NAT instance/gateway configured.

How do you use ECS clusters with private subnets?

like image 993
Ionut Avatar asked Jul 26 '16 20:07

Ionut


4 Answers

PrivateLinks is now available, for both ECS & ECR

With PrivateLinks you can register and operate your EC2 instance and Fargate to ECS cluster without public ip and can also access images from ECR.

Endpoint Required:

For ECS:

EC2 Launch type:

com.amazonaws.region.ecs-agent
com.amazonaws.region.ecs-telemetry
com.amazonaws.region.ecs

Fargate Launch Type:

Just needs ECR & cloudwatch endpoints (mentioned below)

For ECR:

EC2 Launch type:

com.amazonaws.region.ecr.dkr
com.amazonaws.region.ecr.api
com.amazonaws.region.s3 (S3 gateway endpoint)

Fargate Launch Type:

com.amazonaws.region.ecr.dkr 
com.amazonaws.region.s3 (S3 gateway endpoint)

Additionally if you use awslogs driver, you have add cloudwatch endpoint as well. com.amazonaws.Region.logs.

like image 147
Mangal Avatar answered Oct 24 '22 15:10

Mangal


I guess I've found the answer on the AWS documentation and it seems I need to use a NAT instance/Gateway :(

Another source and also the official documentaion

"...Container instances need external network access to communicate with the Amazon ECS service endpoint, so if your container instances are running in a private VPC, they need a network address translation (NAT) instance to provide this access. For more information, see NAT Instances in the Amazon VPC User Guide."

like image 41
Ionut Avatar answered Oct 24 '22 15:10

Ionut


For registering your instance on ECS, you need external connectivity from the instances.

NAT is needed for outgoing connections from the instances on private subnet, but Public IP is not needed.

ECS launches a container in each of your servers which needs to connect to a service for managing state, and for this your instances on your private subnet need connectivity to outer world through NAT.

like image 1
Shibashis Avatar answered Oct 24 '22 17:10

Shibashis


A VPC endpoint for ECS is now available. It's not officially announced, yet (in state "Coming soon" on AWS' public container roadmap).

It will cost minimum around 22$/month (PrivateLink costs for 3 availability zones in us-east, without traffic costs), if they don't state it otherwise.

like image 1
Dominik Avatar answered Oct 24 '22 15:10

Dominik