AWS 最佳实践:我应该在每个 AZ 中有一个 NAT 网关吗?
AWS best practice: shall I have a NAT gateway in each AZ?
由于NAT网关仅在单个AZ内有冗余,如果我想在每个AZ中有一对public/private子网以达到多AZ冗余的目的,我应该在每个AZ中都有一个NAT网关AZ,我不应该吗?
否则,如果我只有一个NAT,如果AZ宕机,所有AZ中的所有子网都会随之宕机,这样就违背了这种多AZ部署的目的。
我是对还是错?
是的,理想情况下,每个可用区 (AZ) 有一个 NAT 网关。
AWS 在 Comparison of NAT Instances and NAT Gateways:
记录了这条建议
Highly available: NAT gateways in each Availability Zone are implemented with redundancy. Create a NAT gateway in each Availability Zone to ensure zone-independent architecture.
单个 AZ 中的单个 NAT 网关仅在该 AZ 内具有冗余,因此如果存在区域问题,则其他 AZ 中的实例将无法路由到互联网。
注意:每个 NAT 网关以及处理的每 GB 数据均按小时收费(参见 VPC Pricing). See How can I reduce data transfer charges for my NAT gateway?
来自AWS官方NAT Gateway doc:
If you have resources in multiple Availability Zones and they share
one NAT gateway, in the event that the NAT gateway's Availability Zone
is down, resources in the other Availability Zones lose internet
access, To create an Availability Zone-independent architecture,
create a NAT gateway in each Availability Zone and configure your
routing to ensure that resources use the NAT gateway in the same
Availability Zone.
NAT 网关为私有子网启用传出 Internet 连接。需要注意的是,您需要为您创建私有子网的每个可用区创建一个 NAT 网关,以实现高可用性。
所描述的网络架构由 public 个子网、私有子网和 HA NAT 网关组成
注意事项
- 如果必须将成本保持在最低水平,那么每个 NAT 网关每月 32.00 美元的基准成本可能会成为阻碍。使用三个 AZ 时,您将为三个 NAT 网关每月支付 96.00 美元。
- NAT 网关还会增加出站流量的成本。您必须为从私有子网流向 Internet 的每 GB 流量支付 0.045 美元的溢价。这将传出流量的成本提高了 50%。
加分!
- Terraform Infra 作为代码模块 simple VPC example
...
azs = ["us-east-1a", "us-east-1b", "us-east-1c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = true
single_nat_gateway = false # to get 1 NGW x AZ
...
参考 Link: https://cloudonaut.io/advanved-aws-networking-pitfalls-that-you-should-avoid/
由于NAT网关仅在单个AZ内有冗余,如果我想在每个AZ中有一对public/private子网以达到多AZ冗余的目的,我应该在每个AZ中都有一个NAT网关AZ,我不应该吗?
否则,如果我只有一个NAT,如果AZ宕机,所有AZ中的所有子网都会随之宕机,这样就违背了这种多AZ部署的目的。
我是对还是错?
是的,理想情况下,每个可用区 (AZ) 有一个 NAT 网关。
AWS 在 Comparison of NAT Instances and NAT Gateways:
记录了这条建议Highly available: NAT gateways in each Availability Zone are implemented with redundancy. Create a NAT gateway in each Availability Zone to ensure zone-independent architecture.
单个 AZ 中的单个 NAT 网关仅在该 AZ 内具有冗余,因此如果存在区域问题,则其他 AZ 中的实例将无法路由到互联网。
注意:每个 NAT 网关以及处理的每 GB 数据均按小时收费(参见 VPC Pricing). See How can I reduce data transfer charges for my NAT gateway?
来自AWS官方NAT Gateway doc:
If you have resources in multiple Availability Zones and they share one NAT gateway, in the event that the NAT gateway's Availability Zone is down, resources in the other Availability Zones lose internet access, To create an Availability Zone-independent architecture, create a NAT gateway in each Availability Zone and configure your routing to ensure that resources use the NAT gateway in the same Availability Zone.
NAT 网关为私有子网启用传出 Internet 连接。需要注意的是,您需要为您创建私有子网的每个可用区创建一个 NAT 网关,以实现高可用性。
所描述的网络架构由 public 个子网、私有子网和 HA NAT 网关组成
注意事项
- 如果必须将成本保持在最低水平,那么每个 NAT 网关每月 32.00 美元的基准成本可能会成为阻碍。使用三个 AZ 时,您将为三个 NAT 网关每月支付 96.00 美元。
- NAT 网关还会增加出站流量的成本。您必须为从私有子网流向 Internet 的每 GB 流量支付 0.045 美元的溢价。这将传出流量的成本提高了 50%。
加分!
- Terraform Infra 作为代码模块 simple VPC example
...
azs = ["us-east-1a", "us-east-1b", "us-east-1c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = true
single_nat_gateway = false # to get 1 NGW x AZ
...
参考 Link: https://cloudonaut.io/advanved-aws-networking-pitfalls-that-you-should-avoid/