|
| 1 | +--- |
| 2 | +title: host-local IP address management plugin |
| 3 | +description: "plugins/ipam/host-local/README.md" |
| 4 | +date: 2020-11-02 |
| 5 | +toc: true |
| 6 | +draft: false |
| 7 | +weight: 200 |
| 8 | +--- |
| 9 | + |
| 10 | +host-local IPAM allocates IPv4 and IPv6 addresses out of a specified address range. Optionally, |
| 11 | +it can include a DNS configuration from a `resolv.conf` file on the host. |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +host-local IPAM plugin allocates ip addresses out of a set of address ranges. |
| 16 | +It stores the state locally on the host filesystem, therefore ensuring uniqueness of IP addresses on a single host. |
| 17 | + |
| 18 | +The allocator can allocate multiple ranges, and supports sets of multiple (disjoint) |
| 19 | +subnets. The allocation strategy is loosely round-robin within each range set. |
| 20 | + |
| 21 | +## Example configurations |
| 22 | + |
| 23 | +Note that the key `ranges` is a list of range sets. That is to say, the length |
| 24 | +of the top-level array is the number of addresses returned. The second-level |
| 25 | +array is a set of subnets to use as a pool of possible addresses. |
| 26 | + |
| 27 | +This example configuration returns 2 IP addresses. |
| 28 | + |
| 29 | +```json |
| 30 | +{ |
| 31 | + "ipam": { |
| 32 | + "type": "host-local", |
| 33 | + "ranges": [ |
| 34 | + [ |
| 35 | + { |
| 36 | + "subnet": "10.10.0.0/16", |
| 37 | + "rangeStart": "10.10.1.20", |
| 38 | + "rangeEnd": "10.10.3.50", |
| 39 | + "gateway": "10.10.0.254" |
| 40 | + }, |
| 41 | + { |
| 42 | + "subnet": "172.16.5.0/24" |
| 43 | + } |
| 44 | + ], |
| 45 | + [ |
| 46 | + { |
| 47 | + "subnet": "3ffe:ffff:0:01ff::/64", |
| 48 | + "rangeStart": "3ffe:ffff:0:01ff::0010", |
| 49 | + "rangeEnd": "3ffe:ffff:0:01ff::0020" |
| 50 | + } |
| 51 | + ] |
| 52 | + ], |
| 53 | + "routes": [ |
| 54 | + { "dst": "0.0.0.0/0" }, |
| 55 | + { "dst": "192.168.0.0/16", "gw": "10.10.5.1" }, |
| 56 | + { "dst": "3ffe:ffff:0:01ff::1/64" } |
| 57 | + ], |
| 58 | + "dataDir": "/run/my-orchestrator/container-ipam-state" |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +Previous versions of the `host-local` allocator did not support the `ranges` |
| 64 | +property, and instead expected a single range on the top level. This is |
| 65 | +deprecated but still supported. |
| 66 | +```json |
| 67 | +{ |
| 68 | + "ipam": { |
| 69 | + "type": "host-local", |
| 70 | + "subnet": "3ffe:ffff:0:01ff::/64", |
| 71 | + "rangeStart": "3ffe:ffff:0:01ff::0010", |
| 72 | + "rangeEnd": "3ffe:ffff:0:01ff::0020", |
| 73 | + "routes": [ |
| 74 | + { "dst": "3ffe:ffff:0:01ff::1/64" } |
| 75 | + ], |
| 76 | + "resolvConf": "/etc/resolv.conf" |
| 77 | + } |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +We can test it out on the command-line: |
| 82 | + |
| 83 | +```bash |
| 84 | +$ echo '{ "cniVersion": "0.3.1", "name": "examplenet", "ipam": { "type": "host-local", "ranges": [ [{"subnet": "203.0.113.0/24"}], [{"subnet": "2001:db8:1::/64"}]], "dataDir": "/tmp/cni-example" } }' | CNI_COMMAND=ADD CNI_CONTAINERID=example CNI_NETNS=/dev/null CNI_IFNAME=dummy0 CNI_PATH=. ./host-local |
| 85 | + |
| 86 | +``` |
| 87 | + |
| 88 | +```json |
| 89 | +{ |
| 90 | + "ips": [ |
| 91 | + { |
| 92 | + "version": "4", |
| 93 | + "address": "203.0.113.2/24", |
| 94 | + "gateway": "203.0.113.1" |
| 95 | + }, |
| 96 | + { |
| 97 | + "version": "6", |
| 98 | + "address": "2001:db8:1::2/64", |
| 99 | + "gateway": "2001:db8:1::1" |
| 100 | + } |
| 101 | + ], |
| 102 | + "dns": {} |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +## Network configuration reference |
| 107 | + |
| 108 | +* `type` (string, required): "host-local". |
| 109 | +* `routes` (string, optional): list of routes to add to the container namespace. Each route is a dictionary with "dst" and optional "gw" fields. If "gw" is omitted, value of "gateway" will be used. |
| 110 | +* `resolvConf` (string, optional): Path to a `resolv.conf` on the host to parse and return as the DNS configuration |
| 111 | +* `dataDir` (string, optional): Path to a directory to use for maintaining state, e.g. which IPs have been allocated to which containers |
| 112 | +* `ranges`, (array, required, nonempty) an array of arrays of range objects: |
| 113 | + * `subnet` (string, required): CIDR block to allocate out of. |
| 114 | + * `rangeStart` (string, optional): IP inside of "subnet" from which to start allocating addresses. Defaults to ".2" IP inside of the "subnet" block. |
| 115 | + * `rangeEnd` (string, optional): IP inside of "subnet" with which to end allocating addresses. Defaults to ".254" IP inside of the "subnet" block for ipv4, ".255" for IPv6 |
| 116 | + * `gateway` (string, optional): IP inside of "subnet" to designate as the gateway. Defaults to ".1" IP inside of the "subnet" block. |
| 117 | + |
| 118 | +Older versions of the `host-local` plugin did not support the `ranges` array. Instead, |
| 119 | +all the properties in the `range` object were top-level. This is still supported but deprecated. |
| 120 | + |
| 121 | +## Supported arguments |
| 122 | +The following [CNI_ARGS](https://github.com/containernetworking/cni/blob/master/SPEC.md#parameters) are supported: |
| 123 | + |
| 124 | +* `ip`: request a specific IP address from a subnet. |
| 125 | + |
| 126 | +The following [args conventions](https://github.com/containernetworking/cni/blob/master/CONVENTIONS.md) are supported: |
| 127 | + |
| 128 | +* `ips` (array of strings): A list of custom IPs to attempt to allocate |
| 129 | + |
| 130 | +The following [Capability Args](https://github.com/containernetworking/cni/blob/master/CONVENTIONS.md) are supported: |
| 131 | + |
| 132 | +* `ipRanges`: The exact same as the `ranges` array - a list of address pools |
| 133 | + |
| 134 | +### Custom IP allocation |
| 135 | +For every requested custom IP, the `host-local` allocator will request that IP |
| 136 | +if it falls within one of the `range` objects. Thus it is possible to specify |
| 137 | +multiple custom IPs and multiple ranges. |
| 138 | + |
| 139 | +If any requested IPs cannot be reserved, either because they are already in use |
| 140 | +or are not part of a specified range, the plugin will return an error. |
| 141 | + |
| 142 | + |
| 143 | +## Files |
| 144 | + |
| 145 | +Allocated IP addresses are stored as files in `/var/lib/cni/networks/$NETWORK_NAME`. |
| 146 | +The path can be customized with the `dataDir` option listed above. Environments |
| 147 | +where IPs are released automatically on reboot (e.g. running containers are not |
| 148 | +restored) may wish to specify `/var/run/cni` or another tmpfs mounted directory |
| 149 | +instead. |
0 commit comments