-
Notifications
You must be signed in to change notification settings - Fork 0
Network mode bridge #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: improvement
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ resource "aws_lb_target_group" "nginx_tg" { | |
| port = 80 | ||
| protocol = "HTTP" | ||
| vpc_id = aws_vpc.main.id | ||
| target_type = "ip" | ||
| target_type = "instance" | ||
| } | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bridge modeの場合インスタンスとポート番号さえわかれば良い |
||
|
|
||
| resource "aws_lb_listener" "nginx_listener" { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,13 @@ resource "aws_security_group" "ecs_instance_sg" { | |
| name_prefix = "ecs-instance-sg-" | ||
| vpc_id = aws_vpc.main.id | ||
|
|
||
| ingress { | ||
| from_port = 32768 | ||
| to_port = 60999 | ||
|
Comment on lines
+43
to
+44
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
上記のように、受け入れる必要があるのはエフェメラルポートだけで十分
とあるが、 sysctl net.ipv4.ip_local_port_rangeでエフェメラルポートは確認可能 |
||
| protocol = "tcp" | ||
| security_groups = [aws_security_group.nginx_sg.id] | ||
| } | ||
|
|
||
| egress { | ||
| from_port = 0 | ||
| to_port = 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ resource "aws_iam_role" "ecs_task_exec" { | |
|
|
||
| resource "aws_ecs_task_definition" "nginx_task" { | ||
| family = "nginx_task" | ||
| network_mode = "awsvpc" | ||
| network_mode = "bridge" | ||
| execution_role_arn = aws_iam_role.ecs_task_exec.arn | ||
| requires_compatibilities = ["EC2"] | ||
| cpu = "256" | ||
|
|
@@ -34,7 +34,7 @@ resource "aws_ecs_task_definition" "nginx_task" { | |
| portMappings = [ | ||
| { | ||
| containerPort = 80 | ||
| hostPort = 80 | ||
| hostPort = 0 | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 動的ポートマッピングによってホスト側のエフェメラルポートを動的に割り当ててくれる |
||
| } | ||
| ] | ||
| logConfiguration = { | ||
|
|
@@ -72,13 +72,9 @@ resource "aws_ecs_service" "nginx_service" { | |
| name = "nginx_service" | ||
| cluster = aws_ecs_cluster.main.id | ||
| task_definition = aws_ecs_task_definition.nginx_task.arn | ||
| desired_count = 2 | ||
| desired_count = 3 | ||
| launch_type = "EC2" | ||
| network_configuration { | ||
| subnets = [aws_subnet.sub.id] | ||
| security_groups = [aws_security_group.ecs_http_sg.id] | ||
| } | ||
| depends_on = [aws_lb_target_group.nginx_tg] | ||
| depends_on = [aws_lb_target_group.nginx_tg] | ||
| load_balancer { | ||
| target_group_arn = aws_lb_target_group.nginx_tg.arn | ||
| container_name = "nginx" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
動的ポートマッピングの場合
ecs-service-schedulerというユーザーが動的にターゲットグループ割り当て時にポートを決定しているのでここのポート指定は結局上書きされるので、ターゲットグループ作成時のポートは実はなんでも良いref: https://dev.classmethod.jp/articles/dynamic-portmapping-elb-ecs/