> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ahmadraza.in/llms.txt
> Use this file to discover all available pages before exploring further.

# PrefixDelegation

# EKS Prefix Delegation - IP Planning Guide

```bash theme={null}
kubectl get nodes -o custom-columns=NAME:.metadata.name,CAPACITY:.status.capacity.pods,ALLOCATABLE:.status.allocatable.pods,AGE:.metadata.creationTimestamp
```

## 📊 **Your Subnet Configuration**

| Subnet   | CIDR             | Available IPs | Availability Zone |
| -------- | ---------------- | ------------- | ----------------- |
| Subnet 1 | `10.50.64.0/20`  | **4,096 IPs** | AZ-1              |
| Subnet 2 | `10.50.112.0/20` | **4,096 IPs** | AZ-2              |
| Subnet 3 | `10.50.16.0/20`  | **4,096 IPs** | AZ-3              |

**Total Available:** \~12,288 IPs across all subnets

***

## 🔄 **How Prefix Delegation Works**

### **Traditional Secondary IP Mode (Before)**

```
Node ENI → Requests individual IPs
├─ Primary IP: 1 IP (for node)
├─ Secondary IP: 1 IP (for pod 1)
├─ Secondary IP: 1 IP (for pod 2)
└─ Secondary IP: 1 IP (for pod 3)
```

### **Prefix Delegation Mode (Now)**

```
Node ENI → Requests /28 prefix (16 IPs at once)
├─ Primary IP: 1 IP (for node)
├─ Prefix 1: /28 = 16 IPs (for 16 pods)
├─ Prefix 2: /28 = 16 IPs (for 16 pods)
└─ Prefix 3: /28 = 16 IPs (for 16 pods)
```

***

## 🖥️ **Your Node Configuration (m6g.large)**

### **Network Interface Limits:**

* **ENIs per node:** 3 ENIs maximum
* **Prefixes per ENI:** 16 prefixes (with prefix delegation)
* **IPs per prefix:** 16 IPs (/28 CIDR block)

### **IP Allocation per Node:**

```
m6g.large Node
├─ ENI 0 (Primary)
│   ├─ 1 Primary IP (node itself)
│   └─ Up to 16 prefixes × 16 IPs = 256 IPs
│
├─ ENI 1 (Secondary)
│   └─ Up to 16 prefixes × 16 IPs = 256 IPs
│
└─ ENI 2 (Secondary)
    └─ Up to 16 prefixes × 16 IPs = 256 IPs

Total theoretical: 1 + (3 ENIs × 16 prefixes × 16 IPs) = 769 IPs
```

**But Kubernetes limits it to \~110 pods per node** (kubelet default)

***

## 💡 **How Your Configuration Works**

### **With WARM\_PREFIX\_TARGET = "1"**

When a node starts:

1. **Initial allocation**: Requests 1 prefix (/28 = 16 IPs) per ENI
   * 3 ENIs × 1 prefix × 16 IPs = **48 IPs reserved initially**
   * Plus 1 primary IP for node = **49 IPs per node**

2. **As pods are scheduled:**
   * When 15 out of 16 IPs in a prefix are used
   * VPC CNI requests another /28 prefix (16 more IPs)
   * Keeps 1 "warm" prefix ready at all times

3. **Maximum allocation per node:**
   * Up to 110 pods (Kubernetes limit)
   * Each pod = 1 IP
   * Actual IPs requested = \~7-8 prefixes × 16 = **112-128 IPs per node**

***

## 📈 **Your Capacity Calculation**

### **Current Node Group (1-2 nodes):**

| Nodes   | IPs Used (Initial)  | IPs Used (Full)       | Subnet Impact |
| ------- | ------------------- | --------------------- | ------------- |
| 2 nodes | 2 × 49 = **98 IPs** | 2 × 128 = **256 IPs** | Minimal       |

### **Scaled Node Group (Max capacity scenarios):**

Let's calculate different scenarios:

#### **Scenario 1: 10 Nodes**

* Initial: 10 × 49 = **490 IPs**
* Full capacity: 10 × 128 = **1,280 IPs**
* Pods: 10 × 110 = **1,100 pods**

#### **Scenario 2: 50 Nodes**

* Initial: 50 × 49 = **2,450 IPs**
* Full capacity: 50 × 128 = **6,400 IPs**
* Pods: 50 × 110 = **5,500 pods**

#### **Scenario 3: 100 Nodes**

* Initial: 100 × 49 = **4,900 IPs**
* Full capacity: 100 × 128 = **12,800 IPs**
* Pods: 100 × 110 = **11,000 pods**

***

## ✅ **Your Subnet Capacity Assessment**

### **Per Subnet (each /20):**

```
Available IPs per subnet: 4,096
Maximum nodes per subnet (at full capacity): ~32 nodes
Maximum pods per subnet: 32 × 110 = ~3,520 pods
```

### **Total Capacity (all 3 subnets):**

```
Total Available IPs: 12,288
Maximum nodes (distributed): ~96 nodes
Maximum pods: 96 × 110 = ~10,560 pods
```

***

## 🎯 **Your Configuration is EXCELLENT! ✅**

### **Why Your Setup Works Well:**

1. **✅ Large Subnets**: /20 subnets are very generous
2. **✅ Multiple AZs**: Distributes load across 3 availability zones
3. **✅ Room to Grow**: Can support \~30 nodes per subnet
4. **✅ Prefix Efficiency**: /28 prefixes align well with your subnet size

***

## 🔍 **Real-World Example**

Let's say you have **2 nodes** (current config):

### **Node 1 in Subnet 1 (10.50.64.0/20):**

```
- Node IP: 10.50.64.10
- Prefix 1 (ENI 0): 10.50.64.16/28 → 10.50.64.16 - 10.50.64.31 (16 IPs)
- Prefix 2 (ENI 1): 10.50.64.32/28 → 10.50.64.32 - 10.50.64.47 (16 IPs)
- Prefix 3 (ENI 2): 10.50.64.48/28 → 10.50.64.48 - 10.50.64.63 (16 IPs)
```

### **Node 2 in Subnet 2 (10.50.112.0/20):**

```
- Node IP: 10.50.112.10
- Prefix 1 (ENI 0): 10.50.112.16/28 → 10.50.112.16 - 10.50.112.31 (16 IPs)
- Prefix 2 (ENI 1): 10.50.112.32/28 → 10.50.112.32 - 10.50.112.47 (16 IPs)
- Prefix 3 (ENI 2): 10.50.112.48/28 → 10.50.112.48 - 10.50.112.63 (16 IPs)
```

Each pod gets one IP from these prefixes automatically!

***

## 📋 **Recommendations**

### **✅ You're Good to Go!**

Your current setup can comfortably support:

* **Short term**: 2-10 nodes (your current plan)
* **Medium term**: 20-30 nodes per subnet
* **Long term**: Up to \~90 nodes total

### **Optional Optimizations:**

If you want to be even more efficient, you could adjust `WARM_PREFIX_TARGET`:

```terraform theme={null}
# More aggressive (saves IPs)
WARM_PREFIX_TARGET = "0"  # Request prefixes only when needed

# Current (balanced)
WARM_PREFIX_TARGET = "1"  # Keep 1 warm prefix ready

# More prefixes (faster pod startup)
WARM_PREFIX_TARGET = "2"  # Keep 2 warm prefixes ready
```

***

## 🚀 **Summary**

**You have PLENTY of IP space!** Your /20 subnets are well-sized for prefix delegation. With your current 2-node setup, you're using less than 0.5% of your subnet capacity. Even scaling to 50+ nodes would still be comfortable.

***

## 📚 **Additional Resources**

* **AWS VPC CNI Prefix Delegation**: [https://docs.aws.amazon.com/eks/latest/userguide/cni-increase-ip-addresses.html](https://docs.aws.amazon.com/eks/latest/userguide/cni-increase-ip-addresses.html)
* **ENI Limits by Instance Type**: [https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html)
* **EKS Best Practices**: [https://aws.github.io/aws-eks-best-practices/](https://aws.github.io/aws-eks-best-practices/)
