To determine the appropriate subnet class for an Amazon EKS (Elastic Kubernetes Service) cluster with 5 nodes, it’s important to account for both the nodes and the additional IP addresses needed for pods and other resources. Here’s a recommended approach:
Calculation and Considerations:
- EKS Node IP Addresses:
- Each node will need its own IP address.
- For 5 nodes, that’s 5 IP addresses.
- Pod IP Addresses:
- By default, the Amazon VPC CNI plugin assigns one IP address per pod from the node’s subnet.
- The number of pods per node depends on your instance type and the configuration of your Kubernetes cluster.
- For example, if you expect each node to host around 20 pods, you’ll need approximately 100 IP addresses for pods.
- Additional Resources:
- Include IP addresses for other resources like load balancers, services, etc.
Subnet Size Recommendation:
A /24 subnet provides 254 usable IP addresses, which is typically sufficient for a small EKS cluster with 5 nodes.
Example Calculation:
- Nodes: 5 IP addresses
- Pods: 100 IP addresses (assuming 20 pods per node)
- Additional Resources: 10 IP addresses (for services, load balancers, etc.)
Total IP Addresses Needed: 5 (nodes) + 100 (pods) + 10 (resources) = 115 IP addresses.
Recommended Subnet Size:
A /24 subnet should be sufficient for this setup:
- CIDR Notation: 192.168.0.0/24
- Total IP Addresses: 256
- Usable IP Addresses: 254
Example Configuration:
- Subnet 1: 192.168.0.0/24
Reasons to Choose a Bigger Subnet (e.g., /22 or /20):
- Future Scalability: If you anticipate significant growth in the number of nodes or pods, a larger subnet will provide ample IP addresses for future expansion without the need to reconfigure your network.
- Flexibility: More IP addresses give you flexibility to add additional resources such as load balancers, services, or new applications.
- Avoiding Exhaustion: Ensuring you have a large pool of IP addresses can prevent issues related to IP address exhaustion, which can disrupt your cluster’s operations.
Example Subnet Sizes:
- /22 Subnet:
- Total IP Addresses: 1,024
- Usable IP Addresses: 1,022
- /20 Subnet:
- Total IP Addresses: 4,096
- Usable IP Addresses: 4,094
When to Consider Smaller Subnets (e.g., /24):
- Small Deployments: If your EKS cluster is small and you do not expect significant growth, a /24 subnet might be sufficient.
- Cost Efficiency: Smaller subnets can sometimes be more cost-effective in environments where IP address scarcity is not a concern.
For an EKS cluster with 5 nodes, I would recommend going with a /22 subnet. This gives you a healthy margin of IP addresses for your nodes, pods, and additional resources while providing room for future growth.