-
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?
Conversation
| from_port = 32768 | ||
| to_port = 60999 |
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.
ロードバランサーからコンテナインスタンスへのインバウンドトラフィックを受け入れるルールを追加します。セキュリティグループとネットワークアクセスコントロールリスト (ネットワーク ACL) では、ロードバランサーからインスタンスへのトラフィックをエフェメラルポート範囲で受け入れる必要があります。
https://repost.aws/ja/knowledge-center/dynamic-port-mapping-ecs
上記のように、受け入れる必要があるのはエフェメラルポートだけで十分
多くの Linux カーネル (Amazon Linux カーネルを含む) は、ポート 32768~61000 を使用します。
https://docs.aws.amazon.com/ja_jp/vpc/latest/userguide/nacl-ephemeral-ports.html
とあるが、
sysctl net.ipv4.ip_local_port_rangeでエフェメラルポートは確認可能
| { | ||
| containerPort = 80 | ||
| hostPort = 80 | ||
| hostPort = 0 |
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.
動的ポートマッピングによってホスト側のエフェメラルポートを動的に割り当ててくれる
|
|
||
| resource "aws_lb_target_group" "nginx_tg" { | ||
| name = "nginx-tg" | ||
| port = 80 |
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/
デフォルトでは、ロードバランサーはターゲットグループの作成時に指定したプロトコルとポート番号を使用して、リクエストをターゲットにルーティングします。または、ターゲットグループへの登録時にターゲットへのトラフィックのルーティングに使用されるポートを上書きすることもできます。
ルーティング設定
| vpc_id = aws_vpc.main.id | ||
| target_type = "ip" | ||
| target_type = "instance" | ||
| } |
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.
bridge modeの場合インスタンスとポート番号さえわかれば良い
一方で、awsvpcの場合タスクごとでENIが異なるのでインスタンスとポート番号だけだとリクエストの送り先が定まらない
Amazon ECS タスク定義のネットワークモードをbridgeにした