-
Notifications
You must be signed in to change notification settings - Fork 202
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
nat gateway for multiple private subnets #42
Comments
However if you do that you will be losing high availability in your system if e.g. you have 3 private subnets each of them in a different availability zone you NAT will be on a public subnet in one of those availability zones which means if that specific availability zone goes down you whole system goes down. I get your point tho I guess a solution could be change
|
Speaking of HA, consider the following
It will generate one public and two private subnet in each availability zone. But it also generate four nat gateway, which is wrong. The AWS documentation is clear about this, nat gateway are bound to public subnet. Even though you have 4 private subnet, you should still have only two nat gateway if you have two public subnet for two availability zone.
Considering that, if multiple private subnet are in the same AZ they can have the same route table ( |
The code associated with this issue is pretty obvious
But it should be
Same issue with EIP that are generated for each NAT Gateway. |
To me it makes more sense to set the number of NATGWs to the number of AZs that you are using. I have trouble thinking of a use case where you would need to have more than one NATGW per AZ. With the current code, I worked around this by setting
In PR #44 the NAT gateways are determined by number of AZs and the routes are determined using logic similar to this workaround. |
You never need more than one NGW per AZ if you setup your routes properly (Each Private SN, if required, should route |
I second @babatundebusari concerns about price, and also second @zot24 HA remark. However, it will not hurt to specify in the readme that the number of Nat gateway IS GOING TO highly impact your final bill on AWS compared to the rest of resources used in this module which are next to free. I understand this issue is addressing 2 things:
My case is slightly different, but I think common to many people, especially the ones starting with small infrastructure requirements. I would like to hear some expert advice about considering a cheaper alternative to use NAT instances (t2.micro or even t2nano) as a cheap alternative to NAT gateway. I would be great to hear pros and cons, so I can better understand. Any answer would be greatly appreciated. I found that this module helps you creating a NAT instance https://github.com/terraform-community-modules/tf_aws_nat |
If price if your concern I wouldn't bother about a NAT I'll secure my instances with SGs and NACLs on a public subnet. If someone find it useful we have create a stack of terraform modules moltin/terraform-stack and individual modules moltin/terraform-modules however it might not be helpful for you @fabriziomoscon as it does create a NAT per private subnet and therefore a public subnet per private one but people could find at least good examples there |
Ok, I think you wanted to write that those repos are NOT useful to me, I had a wonder inside anyway :) good stuff. |
The NAT Gateway that AWS provide you with is an instance with multihoming (or IP Aliasing) and Port Forwarding configured. You can do the same with a regular AWS instance (a while ago, NAT Gateway did not exist). The size of the instance you choose depends on the traffic your instance will have to manage. If that instance is too small, it will result in a network throughput bottleneck. NAT is often perceived (wrongfully) as a security construct. But, having pessimistic NACL and SGs will provide you with more security than a NAT with lax NACL and SGs. |
@fabriziomoscon Since this module provides a
I haven't tested the above, but it should give you an idea - you'd still need to make sure your |
@dyindude thanks!
And it works! |
✨ terraform-community-modules#42 Add support for provisioning only a single NAT Gateway
✨ terraform-community-modules#42 Add support for provisioning only a single NAT Gateway
I have a github repo that I'm using for my terraform studies, in this repo I am creating 1 NAT gateway for each public subnets in each availability zones. In this case I only have 1 public subnet, 1 private subnet, 2 availability zone for a total of 2 NAT gateways. The part that will catch your attention is when you look at the billing the next day, NAT gateways literally consumed more than the ECS containers. My Nat consumed 3.85 USD but by ECS consumed only 0.10 USD. I mean, what gives?
|
@aprilmintacpineda given your use case, you'd probably be better off with a NAT Instance instead of a NAT Gateway. You could select a another cheap TL;DR: NAT Instances allow you to select the instance type you want, because NATing can be achieved with a few kernel and network configuration on a plain old linux box. |
@nap thanks for the tip! |
as we know NAT gateways are not cheap
any way to have an option to use one NAT gateway for multiple private subnets for routing?
will be nice to have in this module
think having like a hundred private subnets..now you get the point
thanks
The text was updated successfully, but these errors were encountered: