|
| 1 | +# IP Reuse (BMH Name-Based Preallocation) |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +IP reuse, also known as BMH Name-Based Preallocation, is a feature that enables |
| 6 | +predictable IP address assignment to BareMetalHosts. This is particularly useful |
| 7 | +during rolling upgrades where you want nodes to retain their IP addresses even |
| 8 | +as the underlying Metal3Machine and Metal3Data objects are recreated. |
| 9 | + |
| 10 | +## Default Behavior (Without BMH Name-Based Preallocation) |
| 11 | + |
| 12 | +As is now, IPPool is an object representing a set of IPAddress pools to be used |
| 13 | +for IPAddress allocations. An IPClaim is an object representing a request for an |
| 14 | +IPAddress allocation. Consequently, the IPClaim object name is structured as |
| 15 | +following: |
| 16 | + |
| 17 | +**IPClaimName** = **Metal3DataName** + **(-)** + **IPPoolName** |
| 18 | + |
| 19 | +Example: metal3datatemplate-0-pool0 |
| 20 | + |
| 21 | +The `Metal3DataName` is derived from the `Metal3DataTemplateName` with an added |
| 22 | +index (`Metal3DataTemplateName-index`), and the `IPPoolName` comes from the |
| 23 | +IPPool object directly. (See the |
| 24 | +[IP Address manager](../ipam/introduction.md) |
| 25 | +for more details on these objects). In the CAPM3 workflow, when a Metal3Machine |
| 26 | +is created and a Metal3Data object is requested, the process of choosing an |
| 27 | +`index` to be appended to the name of the `Metal3DataTemplateName`, is random. |
| 28 | +For example, let's imagine we have two Metal3Machines: `metal3machine-0` and |
| 29 | +`metal3machine-1` which creates the following `metal3datatemplate-0` and |
| 30 | +`metal3datatemplate-1` Metal3Data objects respectively. However, if two nodes |
| 31 | +are being upgraded at a time, there is no guarantee that same indices will be |
| 32 | +appended to the respective objects and in fact it can be in completely reverse |
| 33 | +order (i.e. `metal3machine-0` will get `m3datatemplate-1` and `metal3machine-1` |
| 34 | +will get `m3datatemplate-0`). In order to make it predictable, we structure |
| 35 | +IPClaim object name using the BareMetalHost name, as following: |
| 36 | + |
| 37 | +**IPClaimName** = **BareMetalHostName** + **(-)** + **IPPoolName** |
| 38 | + |
| 39 | +Example: node-0-pool0 |
| 40 | + |
| 41 | +Now, the first part consists of `BareMetalHostName` which is the name of the |
| 42 | +BareMetalHost object, and should always stay the same once created |
| 43 | +(predictable). The second part of it is kept unchanged. |
| 44 | + |
| 45 | +## What is the use of PreAllocations field |
| 46 | + |
| 47 | +Once we have a predictable `IPClaimName`, we can make use of a |
| 48 | +`PreAllocations map[string]IPAddressStr` field in the IPPool object to achieve |
| 49 | +our goal. |
| 50 | + |
| 51 | +We simply add the claim name(s) using the new format (BareMetalHost name |
| 52 | +included) to the `preAllocations` field in the `IPPool`, i.e: |
| 53 | + |
| 54 | +```yaml |
| 55 | +apiVersion: ipam.metal3.io/v1alpha1 |
| 56 | +kind: IPPool |
| 57 | +metadata: |
| 58 | + name: baremetalv4-pool |
| 59 | + namespace: metal3 |
| 60 | +spec: |
| 61 | + clusterName: test1 |
| 62 | + gateway: 192.168.111.1 |
| 63 | + namePrefix: test1-bmv4 |
| 64 | + pools: |
| 65 | + - end: 192.168.111.200 |
| 66 | + start: 192.168.111.100 |
| 67 | + prefix: 24 |
| 68 | + preAllocations: |
| 69 | + node-0-pool0: 192.168.111.101 |
| 70 | + node-1-pool0: 192.168.111.102 |
| 71 | +status: |
| 72 | + indexes: |
| 73 | + node-0-pool0: 192.168.111.101 |
| 74 | + node-1-pool0: 192.168.111.102 |
| 75 | +``` |
| 76 | +
|
| 77 | +Since claim names include BareMetalHost names on them, we are able to predict an |
| 78 | +IPAddress assigned to the specific node. |
| 79 | +
|
| 80 | +## How to Enable BMH Name-Based Preallocation |
| 81 | +
|
| 82 | +To enable the feature, a boolean flag called `enable-bmh-name-based-preallocation` |
| 83 | +was added. It is configurable via clusterctl and it can be passed to the |
| 84 | +clusterctl configuration file by the user. |
| 85 | + |
| 86 | +### Via clusterctl Configuration |
| 87 | + |
| 88 | +Add to your `"${XDG_CONFIG_HOME}"/.config/cluster-api/clusterctl.yaml`: |
| 89 | + |
| 90 | +```yaml |
| 91 | +variables: |
| 92 | + ENABLE_BMH_NAME_BASED_PREALLOCATION: "true" |
| 93 | +``` |
| 94 | + |
| 95 | +### Via Controller Flag |
| 96 | + |
| 97 | +The CAPM3 controller accepts a flag: |
| 98 | + |
| 99 | +```bash |
| 100 | +--enable-bmh-name-based-preallocation=true |
| 101 | +``` |
| 102 | + |
| 103 | +This flag enables the BMH name-based IPClaim naming scheme. |
| 104 | + |
| 105 | +## Use Cases |
| 106 | + |
| 107 | +### Rolling Upgrades with Stable IPs |
| 108 | + |
| 109 | +When performing a rolling upgrade of your cluster: |
| 110 | + |
| 111 | +1. Each BareMetalHost has a stable name (e.g., `node-0`, `node-1`) |
| 112 | +1. With preallocation enabled, IPClaims are named using the BMH name |
| 113 | +1. Pre-populate the IPPool's `preAllocations` field with the desired mappings |
| 114 | +1. As nodes are upgraded, they automatically receive their pre-assigned IPs |
| 115 | + |
| 116 | +### DNS and Certificate Management |
| 117 | + |
| 118 | +Stable IP addresses simplify: |
| 119 | + |
| 120 | +- DNS record management (no need to update records after upgrades) |
| 121 | +- Certificate provisioning (certificates tied to specific IPs remain valid) |
| 122 | +- Firewall rules (static IP-based rules don't need updates) |
| 123 | + |
| 124 | +### Multi-Cluster Deployments |
| 125 | + |
| 126 | +When managing multiple clusters, predictable IPs help with: |
| 127 | + |
| 128 | +- Network segmentation and planning |
| 129 | +- Monitoring and alerting configurations |
| 130 | +- Load balancer backend configurations |
| 131 | + |
| 132 | +## Interaction with Metal3Data Labels |
| 133 | + |
| 134 | +When BMH name-based preallocation is enabled, additional labels are added to |
| 135 | +Metal3Data objects to track the association: |
| 136 | + |
| 137 | +- `infrastructure.cluster.x-k8s.io/data-name` (`DataLabelName`) stores the |
| 138 | + Metal3Data name |
| 139 | +- `infrastructure.cluster.x-k8s.io/pool-name` (`PoolLabelName`) stores the |
| 140 | + referenced pool name |
| 141 | + |
| 142 | +These labels make it possible to track which Metal3Data object and pool were |
| 143 | +used for a given allocation. |
| 144 | + |
| 145 | +## Considerations |
| 146 | + |
| 147 | +### BareMetalHost Naming |
| 148 | + |
| 149 | +For this feature to work effectively: |
| 150 | + |
| 151 | +- BareMetalHost names must be stable and predictable |
| 152 | +- Avoid using generated names that change between deployments |
| 153 | +- Use meaningful names that reflect the physical hardware (e.g., rack position) |
| 154 | + |
| 155 | +### IPPool Configuration |
| 156 | + |
| 157 | +When setting up preAllocations: |
| 158 | + |
| 159 | +- The claim name format is: `{bmh-name}-{pool-name}` |
| 160 | +- Ensure all expected BMH names are covered in the preAllocations map |
| 161 | +- IPs in preAllocations are reserved and won't be allocated to other claims |
| 162 | + |
| 163 | +### Cleanup |
| 164 | + |
| 165 | +When a Metal3Machine is deleted: |
| 166 | + |
| 167 | +- The IPClaim is released |
| 168 | +- The preallocated IP remains reserved in the pool |
| 169 | +- When a new Metal3Machine claims the same BMH, it gets the same IP |
| 170 | + |
| 171 | +## Troubleshooting |
| 172 | + |
| 173 | +### IP Not Being Reused |
| 174 | + |
| 175 | +1. Verify `--enable-bmh-name-based-preallocation` or |
| 176 | + `ENABLE_BMH_NAME_BASED_PREALLOCATION` is enabled |
| 177 | +1. Check that the IPPool `preAllocations` field includes the correct mapping |
| 178 | +1. Verify the claim name format matches: `{bmh-name}-{pool-name}` |
| 179 | + |
| 180 | +### IPClaim Name Mismatch |
| 181 | + |
| 182 | +If IPClaims are not using BMH names: |
| 183 | + |
| 184 | +1. Check controller logs for preallocation-related messages |
| 185 | +1. Verify the `--enable-bmh-name-based-preallocation` flag is properly set on |
| 186 | + the controller deployment |
| 187 | +1. Restart the controller after changing the configuration |
0 commit comments