Categories
Development System & Network

Load balancing for Host network is not working when access within the instance

I have designed this infrastructure.
Initial

ECS SG:

  • Ingress: 0.0.0.0/0
  • Egress: 0.0.0.0/0

ECS Cluster ASG SG:

  • Ingress: 0.0.0.0/0
  • Egress: 0.0.0.0/0

Now when I SSH to instance EC2 No 1. Sometimes I have access to MySQL, sometimes no:

ec2-user@EC2No1 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
ERROR 2003 (HY000): Can't connect to MySQL server on 'loadbalancerdomain.co.uk' (110)

ec2-user@EC2No1 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.

ec2-user@EC2No1 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
ERROR 2003 (HY000): Can't connect to MySQL server on 'loadbalancerdomain.co.uk' (110)

ec2-user@EC2No1 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
ERROR 2003 (HY000): Can't connect to MySQL server on 'loadbalancerdomain.co.uk' (110)

ec2-user@EC2No1 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.

Now I do the modification for the infrastructure:

enter image description here

I have no access to MySQL from instance 1, I have access to MySQL from instance 2

Instance 1

ec2-user@EC2No1 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
ERROR 2003 (HY000): Can't connect to MySQL server on 'loadbalancerdomain.co.uk' (110)

ec2-user@EC2No1 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
ERROR 2003 (HY000): Can't connect to MySQL server on 'loadbalancerdomain.co.uk' (110)

ec2-user@EC2No1 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
ERROR 2003 (HY000): Can't connect to MySQL server on 'loadbalancerdomain.co.uk' (110)

Instance 2

ec2-user@EC2No2 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.


ec2-user@EC2No2 $ mysql -u root -hloadbalancerdomain.co.uk -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.

Target group:
TG1
TG2
Task definition network mode: HOST

Question

How Can I fix this?

The problem does not exists with the awsvpc network mode for task definition, but I need to scale instances up to use this mode.

Leave a Reply

Your email address will not be published. Required fields are marked *