I'm exploring using the new Fargate option for my ECS containers. One constraint is that the running task must always be accessible at the same Public IP address.
My first thought was to allocate an Elastic IP but I can't tell what to associate it to. It seems an Elastic IP can be associated to an instance (which is irrelevant for Fargate) or a Network Interface. However, if I associate it with an ENI, I can't see how to ensure my task's container has that Network Interface. When creating a Service, I see that I can put it in a VPC, but that's it.
From experimentation, if I kill a task so that the service restarts a new one, or if I update the service to run a new task revision - the container that starts running the new task will have a new ENI each time.
Is there some way to ensure that a given service has the same public IP address, even if its tasks are killed and restarted?
To associate an Elastic IP address with an instance Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Elastic IPs. Select an Elastic IP address and choose Actions, Associate address. Select the instance from Instance and then choose Associate.
Click the Elastic IPs link in the EC2 Dashboard. Click Allocate New Address and choose VPC or EC2 from the drop-down list, depending whether you're going to associate this IP with an instance in Amazon EC2-Virtual Private Cloud (VPC) or Amazon EC2-Classic, respectively. Click Yes, Allocate to confirm your choice.
I can confirm, yes you can SSH into a Fargate container by running sshd and properly configuring the security group.
Actually your can do it with Network Load balancer. It is a special type of load balancer, where elastic IP can be added. This instruction can really help https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html
Fargate does not currently support ENI assignment, so it is not possible to have an Elastic IP associated with a Fargate task definition.
The only way you can use a static IP address with Fargate is via the Application Load Balancer with an alias.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With