blob: b6799961c1d42c343f8302842d983eef002ea167 [file] [log] [blame]
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +02001Contiv/VPP Network Operation
2============================
3
4This document describes the network operation of the Contiv/VPP k8s
5network plugin. It elaborates the operation and config options of the
6Contiv IPAM, as well as details on how the VPP gets programmed by
7Contiv/VPP control plane.
8
9The following picture shows 2-node k8s deployment of Contiv/VPP, with a
10VXLAN tunnel established between the nodes to forward inter-node POD
11traffic. The IPAM options are depicted on the Node 1, whereas the VPP
12programming is depicted on the Node 2.
13
14.. figure:: /_images/contiv-networking.png
15 :alt: contiv-networking.png
16
17 Contiv/VPP Architecture
18
19Contiv/VPP IPAM (IP Address Management)
20---------------------------------------
21
22IPAM in Contiv/VPP is based on the concept of **Node ID**. The Node ID
23is a number that uniquely identifies a node in the k8s cluster. The
24first node is assigned the ID of 1, the second node 2, etc. If a node
25leaves the cluster, its ID is released back to the pool and will be
26re-used by the next node.
27
28The Node ID is used to calculate per-node IP subnets for PODs and other
29internal subnets that need to be unique on each node. Apart from the
30Node ID, the input for IPAM calculations is a set of config knobs, which
31can be specified in the ``IPAMConfig`` section of the [Contiv/VPP
32deployment YAML](../../../k8s/contiv-vpp.yaml):
33
34- **PodSubnetCIDR** (default ``10.1.0.0/16``): each pod gets an IP
35 address assigned from this range. The size of this range (default
36 ``/16``) dictates upper limit of POD count for the entire k8s cluster
37 (default 65536 PODs).
38
39- **PodNetworkPrefixLen** (default ``24``): per-node dedicated
40 podSubnet range. From the allocatable range defined in
41 ``PodSubnetCIDR``, this value will dictate the allocation for each
42 node. With the default value (``24``) this indicates that each node
43 has a ``/24`` slice of the ``PodSubnetCIDR``. The Node ID is used to
44 address the node. In case of ``PodSubnetCIDR = 10.1.0.0/16``,
45 ``PodNetworkPrefixLen = 24`` and ``NodeID = 5``, the resulting POD
46 subnet for the node would be ``10.1.5.0/24``.
47
48- **PodIfIPCIDR** (default ``10.2.1.0/24``): VPP-internal addresses put
49 the VPP interfaces facing towards the PODs into L3 mode. This IP
50 range will be reused on each node, thereby it is never externally
51 addressable outside of the node itself. The only requirement is that
52 this subnet should not collide with any other IPAM subnet.
53
54- **VPPHostSubnetCIDR** (default ``172.30.0.0/16``): used for
55 addressing the interconnect of VPP with the Linux network stack,
56 within the same node. Since this subnet needs to be unique on each
57 node, the Node ID is used to determine the actual subnet used on the
58 node with the combination of ``VPPHostNetworkPrefixLen``,
59 ``PodSubnetCIDR`` and ``PodNetworkPrefixLen``.
60
61- **VPPHostNetworkPrefixLen** (default ``24``): used to calculate the
62 subnet for addressing the interconnect of VPP with the Linux network
63 stack, within the same node. With
64 ``VPPHostSubnetCIDR = 172.30.0.0/16``,
65 ``VPPHostNetworkPrefixLen = 24`` and ``NodeID = 5`` the resulting
66 subnet for the node would be ``172.30.5.0/24``.
67
68- **NodeInterconnectCIDR** (default ``192.168.16.0/24``): range for the
69 addresses assigned to the data plane interfaces managed by VPP.
70 Unless DHCP is used (``NodeInterconnectDHCP = True``), the Contiv/VPP
71 control plane automatically assigns an IP address from this range to
72 the DPDK-managed ethernet interface bound to VPP on each node. The
73 actual IP address will be calculated from the Node ID (e.g., with
74 ``NodeInterconnectCIDR = 192.168.16.0/24`` and ``NodeID = 5``, the
75 resulting IP address assigned to the ethernet interface on VPP will
76 be ``192.168.16.5`` ).
77
78- **NodeInterconnectDHCP** (default ``False``): instead of assigning
79 the IPs for the data plane interfaces, which are managed by VPP from
80 ``NodeInterconnectCIDR`` by the Contiv/VPP control plane, DHCP
81 assigns the IP addresses. The DHCP must be running in the network
82 where the data plane interface is connected, in case
83 ``NodeInterconnectDHCP = True``, ``NodeInterconnectCIDR`` is ignored.
84
85- **VxlanCIDR** (default ``192.168.30.0/24``): in order to provide
86 inter-node POD to POD connectivity via any underlay network (not
87 necessarily an L2 network), Contiv/VPP sets up a VXLAN tunnel overlay
88 between each of the 2 nodes within the cluster. Each node needs its
89 unique IP address of the VXLAN BVI interface. This IP address is
90 automatically calculated from the Node ID, (e.g., with
91 ``VxlanCIDR = 192.168.30.0/24`` and ``NodeID = 5``, the resulting IP
92 address assigned to the VXLAN BVI interface will be
93 ``192.168.30.5``).
94
95VPP Programming
96---------------
97
98This section describes how the Contiv/VPP control plane programs VPP,
99based on the events it receives from k8s. This section is not
100necessarily for understanding basic Contiv/VPP operation, but is very
101useful for debugging purposes.
102
103Contiv/VPP currently uses a single VRF to forward the traffic between
104PODs on a node, PODs on different nodes, host network stack, and
105DPDK-managed dataplane interface. The forwarding between each of them is
106purely L3-based, even for cases of communication between 2 PODs within
107the same node.
108
109DPDK-Managed Data Interface
110~~~~~~~~~~~~~~~~~~~~~~~~~~~
111
112In order to allow inter-node communication between PODs on different
113nodes and between PODs and outside world, Contiv/VPP uses data-plane
114interfaces bound to VPP using DPDK. Each node should have one main VPP
115interface, which is unbound from the host network stack and bound to
116VPP. The Contiv/VPP control plane automatically configures the interface
117either via DHCP, or with a statically assigned address (see
118``NodeInterconnectCIDR`` and ``NodeInterconnectDHCP`` yaml settings).
119
120PODs on the Same Node
121~~~~~~~~~~~~~~~~~~~~~
122
123PODs are connected to VPP using virtio-based TAP interfaces created by
124VPP, with the POD-end of the interface placed into the POD container
125network namespace. Each POD is assigned an IP address from the
126``PodSubnetCIDR``. The allocated IP is configured with the prefix length
127``/32``. Additionally, a static route pointing towards the VPP is
128configured in the POD network namespace. The prefix length ``/32`` means
129that all IP traffic will be forwarded to the default route - VPP. To get
130rid of unnecessary broadcasts between POD and VPP, a static ARP entry is
131configured for the gateway IP in the POD namespace, as well as for POD
132IP on VPP. Both ends of the TAP interface have a static (non-default)
133MAC address applied.
134
135PODs with hostNetwork=true
136~~~~~~~~~~~~~~~~~~~~~~~~~~
137
138PODs with a ``hostNetwork=true`` attribute are not placed into a
139separate network namespace, they instead use the main host Linux network
140namespace; therefore, they are not directly connected to the VPP. They
141rely on the interconnection between the VPP and the host Linux network
142stack, which is described in the next paragraph. Note, when these PODs
143access some service IP, their network communication will be NATed in
144Linux (by iptables rules programmed by kube-proxy) as opposed to VPP,
145which is the case for the PODs connected to VPP directly.
146
147Linux Host Network Stack
148~~~~~~~~~~~~~~~~~~~~~~~~
149
150In order to interconnect the Linux host network stack with VPP (to allow
151access to the cluster resources from the host itself, as well as for the
152PODs with ``hostNetwork=true``), VPP creates a TAP interface between VPP
153and the main network namespace. The TAP interface is configured with IP
154addresses from the ``VPPHostSubnetCIDR`` range, with ``.1`` in the
155latest octet on the VPP side, and ``.2`` on the host side. The name of
156the host interface is ``vpp1``. The host has static routes pointing to
157VPP configured with: - A route to the whole ``PodSubnetCIDR`` to route
158traffic targeting PODs towards VPP. - A route to ``ServiceCIDR``
159(default ``10.96.0.0/12``), to route service IP targeted traffic that
160has not been translated by kube-proxy for some reason towards VPP. - The
161host also has a static ARP entry configured for the IP of the VPP-end
162TAP interface, to get rid of unnecessary broadcasts between the main
163network namespace and VPP.
164
165VXLANs to Other Nodes
166~~~~~~~~~~~~~~~~~~~~~
167
168In order to provide inter-node POD to POD connectivity via any underlay
169network (not necessarily an L2 network), Contiv/VPP sets up a VXLAN
170tunnel overlay between each 2 nodes within the cluster (full mesh).
171
172All VXLAN tunnels are terminated in one bridge domain on each VPP. The
173bridge domain has learning and flooding disabled, the l2fib of the
174bridge domain contains a static entry for each VXLAN tunnel. Each bridge
175domain has a BVI interface, which interconnects the bridge domain with
176the main VRF (L3 forwarding). This interface needs a unique IP address,
177which is assigned from the ``VxlanCIDR`` as describe above.
178
179The main VRF contains several static routes that point to the BVI IP
180addresses of other nodes. For each node, it is a route to PODSubnet and
181VppHostSubnet of the remote node, as well as a route to the management
182IP address of the remote node. For each of these routes, the next hop IP
183is the BVI interface IP of the remote node, which goes via the BVI
184interface of the local node.
185
186The VXLAN tunnels and the static routes pointing to them are
187added/deleted on each VPP, whenever a node is added/deleted in the k8s
188cluster.
189
190More Info
191~~~~~~~~~
192
193Please refer to the [Packet Flow Dev
194Guide](../dev-guide/PACKET_FLOW.html) for more detailed description of
195paths traversed by request and response packets inside Contiv/VPP
196Kubernetes cluster under different situations.