1
1
# Network Connectivity for Clones
2
2
3
- This document presents the strategy to ensure continued network connectivity for
4
- multiple clones created from a single Firecracker microVM snapshot. This
5
- document also provides an overview of the scalability benchmarks we performed.
3
+ This document presents a strategy to ensure continued network connectivity for
4
+ multiple clones created from a single Firecracker microVM snapshot.
5
+
6
+ > \[ !CAUTION\]
7
+ > This should be considered as just an example to get you started, and we don't
8
+ > claim this is a performant or secure setup.
6
9
7
10
## Setup
8
11
@@ -13,14 +16,7 @@ names, and each guest will be resumed with the same network configuration, most
13
16
importantly with the same IP address(es). To work around the former, each clone
14
17
should be started within a separate network namespace (we can have multiple TAP
15
18
interfaces with the same name, as long as they reside in distinct network
16
- namespaces). The latter can be mitigated by leveraging ` iptables ` ` SNAT ` and
17
- ` DNAT ` support. We choose a clone address (** CA** ) for each clone, which is the
18
- new address that’s going to represent the guest, and make it so all packets
19
- leaving the VM have their source address rewritten to CA, and all incoming
20
- packets with the destination address equal to CA have it rewritten to the IP
21
- address configured inside the guest (which remains the same for all clones).
22
- Each individual clone continues to believe it’s using the original address, but
23
- outside the VM packets are assigned a different one for every clone.
19
+ namespaces). The latter can be mitigated by leveraging ` iptables ` ` NAT ` support.
24
20
25
21
Let’s have a more detailed look at this approach. We assume each VM has a single
26
22
network interface attached. If multiple interfaces with full connectivity are
@@ -37,8 +33,8 @@ corresponding virtio device (referred to as the guest IP address, for example
37
33
Attempting to restore multiple clones from the same snapshot faces the problem
38
34
of every single one of them attempting to use a TAP device with the original
39
35
name, which is not possible by default. Therefore, we need to start each clone
40
- in a separate network namespace. This is already possible using the netns jailer
41
- parameter, described in the [ documentation] ( ../jailer.md ) . The specified
36
+ in a separate network namespace. This is already possible using the ` -- netns`
37
+ jailer parameter, described in the [ documentation] ( ../jailer.md ) . The specified
42
38
namespace must already exist, so we have to create it first using
43
39
44
40
``` bash
@@ -94,9 +90,7 @@ use the following commands (for namespace `fc0`):
94
90
95
91
``` bash
96
92
# create the veth pair inside the namespace
97
- sudo ip netns exec fc0 ip link add veth1 type veth peer name veth0
98
- # move veth1 to the global host namespace
99
- sudo ip netns exec fc0 ip link set veth1 netns 1
93
+ sudo ip link add name veth1 type veth peer name veth0 netns fc0
100
94
101
95
sudo ip netns exec fc0 ip addr add 10.0.0.2/24 dev veth0
102
96
sudo ip netns exec fc0 ip link set dev veth0 up
@@ -108,31 +102,32 @@ sudo ip link set dev veth1 up
108
102
sudo ip netns exec fc0 ip route add default via 10.0.0.1
109
103
```
110
104
111
- ### ` iptables ` rules for end-to-end connectivity
105
+ ### ` iptables ` rules for VM egress connectivity
112
106
113
107
The last step involves adding the ` iptables ` rules which change the
114
108
source/destination IP address of packets on the fly (thus allowing all clones to
115
- have the same internal IP). We need to choose a clone address, which is unique
116
- on the host for each VM. In the demo, we use
117
- ` 192.168.<idx / 30>.<(idx % 30) * 8 + 3> ` (which is ` 192.168.0.3 ` for
118
- ` clone 0 ` ):
109
+ have the same internal IP).
110
+
111
+ ``` sh
112
+ # Find the host egress device
113
+ UPSTREAM=$( ip -j route list default | jq -r ' .[0].dev' )
114
+ # anything coming from the VMs, we NAT the address
115
+ iptables -t nat -A POSTROUTING -s 10.0.0.0/30 -o $UPSTREAM -j MASQUERADE
116
+ # forward packets by default
117
+ iptables -P FORWARD ACCEPT
118
+ ip netns exec fc0 ip route add default via 10.0.0.1
119
+ ip netns exec fc0 iptables -P FORWARD ACCEPT
120
+ ```
121
+
122
+ You may also want to configure the guest with a default route and a DNS
123
+ nameserver:
119
124
120
125
``` bash
121
- # for packets that leave the namespace and have the source IP address of the
122
- # original guest, rewrite the source address to clone address 192.168.0.3
123
- sudo ip netns exec fc0 iptables -t nat -A POSTROUTING -o veth0 \
124
- -s 192.168.241.2 -j SNAT --to 192.168.0.3
125
-
126
- # do the reverse operation; rewrites the destination address of packets
127
- # heading towards the clone address to 192.168.241.2
128
- sudo ip netns exec fc0 iptables -t nat -A PREROUTING -i veth0 \
129
- -d 192.168.0.3 -j DNAT --to 192.168.241.2
130
-
131
- # (adds a route on the host for the clone address)
132
- sudo ip route add 192.168.0.3 via 10.0.0.2
126
+ ip route default via 10.0.0.1
127
+ echo nameserver 8.8.8.8 > /etc/resolv.conf
133
128
```
134
129
135
- ** Full connectivity to/ from the clone should be present at this point.**
130
+ ** Connectivity from the clone should be present at this point.**
136
131
137
132
To make sure the guest also adjusts to the new environment, you can explicitly
138
133
clear the ARP/neighbour table in the guest:
@@ -146,47 +141,39 @@ Otherwise, packets originating from the guest might be using old Link Layer
146
141
Address for up to arp cache timeout seconds. After said timeout period,
147
142
connectivity will work both ways even without an explicit flush.
148
143
149
- ## Scalability evaluation
150
-
151
- We ran synthetic tests to determine the impact of the addtional iptables rules
152
- and namespaces on network performance. We compare the case where each VM runs as
153
- regular Firecracker (gets assigned a TAP interface and a unique IP address in
154
- the global namespace) versus the setup with a separate network namespace for
155
- each VM (together with the veth pair and additional rules). We refer to the
156
- former as the basic case, while the latter is the ns case. We measure latency
157
- with the ` ping ` command and throughput with ` iperf ` .
158
-
159
- The experiments, ran on an Amazon AWS ` m5d.metal ` EC2 instace, go as follows:
160
-
161
- - Set up 3000 network resource slots (different TAP interfaces for the basic
162
- case, and namespaces + everything else for ns). This is mainly to account for
163
- any difference the setup itself might make, even if there are not as many
164
- active endpoints at any given time.
165
- - Start 1000 Firecracker VMs, and pick ` N < 1000 ` as the number of active VMs
166
- that are going to generate network traffic. For ping experiments, we ping each
167
- active VM from the host every 500ms for 30 seconds. For ` iperf ` experiments,
168
- we measure the average bandwidth of connections from the host to every active
169
- VM lasting 40 seconds. There is one separate client process per VM.
170
- - When ` N = 100 ` , in the basic case we get average latencies of
171
- ` 0.315 ms (0.160/0.430 min/max) ` for ` ping ` , and an average throughput of
172
- ` 2.25 Gbps (1.62/3.21 min/max) ` per VM for ` iperf ` . In the ns case, the ping
173
- results ** are bumped higher by around 10-20 us** , while the ` iperf ` results
174
- are virtually the same on average, with a higher minimum (1.73 Gbps) and a
175
- lower maximum (3 Gbps).
176
- - When ` N = 1000 ` , we start facing desynchronizations caused by difficulties in
177
- starting (and thus finishing) the client processes all at the same time, which
178
- creates a wider distribution of results. In the basic case, the average
179
- latency for ping experiments has gone down to 0.305 ms, the minimum decreased
180
- to 0.155 ms, but the maximum increased to 0.640 ms. The average ` iperf ` per VM
181
- throughput is around ` 440 Mbps (110/3936 min/max) ` . In the ns case, average
182
- ` ping ` latency is now ` 0.318 ms (0.170/0.650 min/max) ` . For ` iperf ` , the
183
- average throughput is very close to basic at ` ~430 Mbps ` , while the minimum
184
- and maximum values are lower at ` 85/3803 Mbps ` .
185
-
186
- ** The above measurements give a significant degree of confidence in the
187
- scalability of the solution** (subject to repeating for different values of the
188
- experimental parameters, if necessary). The increase in latency is almost
189
- negligible considering usual end-to-end delays. The lower minimum throughput
190
- from the iperf measurements might be significant, but only if that magnitude of
191
- concurrent, data-intensive transfers is likely. Moreover, the basic measurements
192
- are close to an absolute upper bound.
144
+ # Ingress connectivity
145
+
146
+ The above setup only provides egress connectivity. If in addition we also want
147
+ to add ingress (in other words, make the guest VM routable outside the network
148
+ namespace), then we need to choose a "clone address" that will represent this VM
149
+ uniquely. For our example we can use IPs from ` 172.16.0.0/12 ` , for example
150
+ ` 172.16.0.1 ` .
151
+
152
+ Then we can rewrite destination address heading towards the "clone address" to
153
+ the guest IP.
154
+
155
+ ``` bash
156
+ ip netns exec fc0 iptables -t nat -A PREROUTING -i veth0 \
157
+ -d 172.16.0.1 -j DNAT --to 192.168.241.2
158
+ ```
159
+
160
+ And add a route on the host so we can access the guest VM from the host network
161
+ namespace:
162
+
163
+ ``` bash
164
+ ip route add 172.16.0.1 via 10.0.0.2
165
+ ```
166
+
167
+ To confirm that ingress connectivity works, try
168
+
169
+ ``` bash
170
+ ping 172.16.0.1
171
+ # or
172
+ ssh root@172.16.0.1
173
+ ```
174
+
175
+ # See also
176
+
177
+ For an improved setup with full ingress and egress connectivity to the
178
+ individual VMs, see
179
+ [ this discussion] ( https://github.com/firecracker-microvm/firecracker/discussions/4720 ) .
0 commit comments