Skip to content

Commit 8f9729a

Browse files
lucasmundimmurali-reddy
authored andcommitted
Introduces the option --overlay-type={subnet,full}, to be able to always generate IPIP tunnels regardless of node subnets (#666)
* Introduces the option --full-overlay, to always generate IPIP tunnels regardless of node subnets * Use --overlay-type={subnet,full} instead of --full-overlay={true,false}
1 parent fac0663 commit 8f9729a

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

docs/user-guide.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Usage of kube-router:
4949
--disable-source-dest-check Disable the source-dest-check attribute for AWS EC2 instances. When this option is false, it must be set some other way. (default true)
5050
--enable-cni Enable CNI plugin. Disable if you want to use kube-router features alongside another CNI plugin. (default true)
5151
--enable-ibgp Enables peering with nodes with the same ASN, if disabled will only peer with external BGP peers (default true)
52-
--enable-overlay When enable-overlay set to true, IP-in-IP tunneling is used for pod-to-pod networking across nodes in different subnets. When set to false no tunneling is used and routing infrastrcture is expected to route traffic for pod-to-pod networking across nodes in different subnets (default true)
52+
--enable-overlay When enable-overlay is set to true, IP-in-IP tunneling is used for pod-to-pod networking across nodes in different subnets. When set to false no tunneling is used and routing infrastructure is expected to route traffic for pod-to-pod networking across nodes in different subnets (default true)
5353
--enable-pod-egress SNAT traffic from Pods to destinations outside the cluster. (default true)
5454
--enable-pprof Enables pprof for debugging performance and memory leak issues.
5555
--hairpin-mode Add iptables rules for every Service Endpoint to support hairpin traffic.
@@ -65,6 +65,7 @@ Usage of kube-router:
6565
--metrics-port uint16 Prometheus metrics port, (Default 0, Disabled)
6666
--nodeport-bindon-all-ip For service of NodePort type create IPVS service that listens on all IP's of the node.
6767
--nodes-full-mesh Each node in the cluster will setup BGP peering with rest of the nodes. (default true)
68+
--overlay-type string Possible values: subnet,full - When set to "subnet", the default, default "--enable-overlay=true" behavior is used. When set to "full", it changes "--enable-overlay=true" default behavior so that IP-in-IP tunneling is used for pod-to-pod networking across nodes regardless of the subnet the nodes are in. (default "subnet")
6869
--override-nexthop Override the next-hop in bgp routes sent to peers with the local ip.
6970
--peer-router-asns uints ASN numbers of the BGP peer to which cluster nodes will advertise cluster ip and node's pod cidr. (default [])
7071
--peer-router-ips ipSlice The ip address of the external router to which all nodes will peer and advertise the cluster ip and pod cidr's. (default [])

pkg/controllers/routing/network_routes_controller.go

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type NetworkRoutingController struct {
9191
bgpGracefulRestart bool
9292
ipSetHandler *utils.IPSet
9393
enableOverlays bool
94+
overlayType string
9495
peerMultihopTTL uint8
9596
MetricsEnabled bool
9697
bgpServerStarted bool
@@ -410,50 +411,41 @@ func (nrc *NetworkRoutingController) injectRoute(path *table.Path) error {
410411
dst, _ := netlink.ParseIPNet(nlri.String())
411412
var route *netlink.Route
412413

413-
// check if the neighbour is in same subnet. If node is not in same subnet and --override-nexthop=false
414-
// only then create IPIP tunnels
415-
if !nrc.nodeSubnet.Contains(nexthop) && !nrc.overrideNextHop {
416-
tunnelName := generateTunnelName(nexthop.String())
417-
glog.Infof("Found node: " + nexthop.String() + " to be in different subnet.")
418-
419-
// if overlay is not enabled then skip creating tunnels and adding route
420-
if !nrc.enableOverlays {
421-
glog.Infof("Found node: " + nexthop.String() + " to be in different subnet but overlays are " +
422-
"disabled so not creating any tunnel and injecting route for the node's pod CIDR.")
423-
424-
glog.Infof("Cleaning up old routes if there are any")
425-
routes, err := netlink.RouteListFiltered(nl.FAMILY_ALL, &netlink.Route{
426-
Dst: dst, Protocol: 0x11,
427-
}, netlink.RT_FILTER_DST|netlink.RT_FILTER_PROTOCOL)
428-
if err != nil {
429-
glog.Errorf("Failed to get routes from netlink")
430-
}
431-
for i, r := range routes {
432-
glog.V(2).Infof("Found route to remove: %s", r.String())
433-
err := netlink.RouteDel(&routes[i])
434-
if err != nil {
435-
glog.Errorf("Failed to remove route due to " + err.Error())
436-
}
437-
}
414+
tunnelName := generateTunnelName(nexthop.String())
415+
sameSubnet := nrc.nodeSubnet.Contains(nexthop)
438416

439-
glog.Infof("Cleaning up if there is any existing tunnel interface for the node")
440-
link, err := netlink.LinkByName(tunnelName)
441-
if err != nil {
442-
return nil
417+
// cleanup route and tunnel if overlay is disabled or node is in same subnet and overlay-type is set to 'subnet'
418+
if !nrc.enableOverlays || (sameSubnet && nrc.overlayType == "subnet") {
419+
glog.Infof("Cleaning up old routes if there are any")
420+
routes, err := netlink.RouteListFiltered(nl.FAMILY_ALL, &netlink.Route{
421+
Dst: dst, Protocol: 0x11,
422+
}, netlink.RT_FILTER_DST|netlink.RT_FILTER_PROTOCOL)
423+
if err != nil {
424+
glog.Errorf("Failed to get routes from netlink")
425+
}
426+
for i, r := range routes {
427+
glog.V(2).Infof("Found route to remove: %s", r.String())
428+
if err := netlink.RouteDel(&routes[i]); err != nil {
429+
glog.Errorf("Failed to remove route due to " + err.Error())
443430
}
444-
err = netlink.LinkDel(link)
445-
if err != nil {
431+
}
432+
433+
glog.Infof("Cleaning up if there is any existing tunnel interface for the node")
434+
if link, err := netlink.LinkByName(tunnelName); err == nil {
435+
if err = netlink.LinkDel(link); err != nil {
446436
glog.Errorf("Failed to delete tunnel link for the node due to " + err.Error())
447437
}
448-
return nil
449438
}
439+
}
450440

441+
// create IPIP tunnels only when node is not in same subnet or overlay-type is set to 'full'
442+
// prevent creation when --override-nexthop=true as well
443+
if (!sameSubnet || nrc.overlayType == "full") && !nrc.overrideNextHop {
451444
// create ip-in-ip tunnel and inject route as overlay is enabled
452445
var link netlink.Link
453446
var err error
454447
link, err = netlink.LinkByName(tunnelName)
455448
if err != nil {
456-
glog.Infof("Found node: " + nexthop.String() + " to be in different subnet. Creating tunnel: " + tunnelName)
457449
out, err := exec.Command("ip", "tunnel", "add", tunnelName, "mode", "ipip", "local", nrc.nodeIP.String(),
458450
"remote", nexthop.String(), "dev", nrc.nodeInterface).CombinedOutput()
459451
if err != nil {
@@ -938,6 +930,7 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
938930
nrc.advertiseLoadBalancerIP = kubeRouterConfig.AdvertiseLoadBalancerIp
939931
nrc.advertisePodCidr = kubeRouterConfig.AdvertiseNodePodCidr
940932
nrc.enableOverlays = kubeRouterConfig.EnableOverlay
933+
nrc.overlayType = kubeRouterConfig.OverlayType
941934

942935
nrc.bgpPort = kubeRouterConfig.BGPPort
943936

pkg/options/options.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"net"
55
"time"
66

7-
"github.com/spf13/pflag"
87
"strconv"
8+
9+
"github.com/spf13/pflag"
910
)
1011

1112
const DEFAULT_BGP_PORT = 179
@@ -28,6 +29,7 @@ type KubeRouterConfig struct {
2829
EnablePodEgress bool
2930
EnablePprof bool
3031
FullMeshMode bool
32+
OverlayType string
3133
GlobalHairpinMode bool
3234
HealthPort uint16
3335
HelpRequested bool
@@ -64,6 +66,7 @@ func NewKubeRouterConfig() *KubeRouterConfig {
6466
IPTablesSyncPeriod: 5 * time.Minute,
6567
RoutesSyncPeriod: 5 * time.Minute,
6668
EnableOverlay: true,
69+
OverlayType: "subnet",
6770
}
6871
}
6972

@@ -134,8 +137,12 @@ func (s *KubeRouterConfig) AddFlags(fs *pflag.FlagSet) {
134137
fs.BoolVar(&s.NodePortBindOnAllIp, "nodeport-bindon-all-ip", false,
135138
"For service of NodePort type create IPVS service that listens on all IP's of the node.")
136139
fs.BoolVar(&s.EnableOverlay, "enable-overlay", true,
137-
"When enable-overlay set to true, IP-in-IP tunneling is used for pod-to-pod networking across nodes in different subnets. "+
138-
"When set to false no tunneling is used and routing infrastrcture is expected to route traffic for pod-to-pod networking across nodes in different subnets")
140+
"When enable-overlay is set to true, IP-in-IP tunneling is used for pod-to-pod networking across nodes in different subnets. "+
141+
"When set to false no tunneling is used and routing infrastructure is expected to route traffic for pod-to-pod networking across nodes in different subnets")
142+
fs.StringVar(&s.OverlayType, "overlay-type", s.OverlayType,
143+
"Possible values: subnet,full - "+
144+
"When set to \"subnet\", the default, default \"--enable-overlay=true\" behavior is used. "+
145+
"When set to \"full\", it changes \"--enable-overlay=true\" default behavior so that IP-in-IP tunneling is used for pod-to-pod networking across nodes regardless of the subnet the nodes are in.")
139146
fs.StringSliceVar(&s.PeerPasswords, "peer-router-passwords", s.PeerPasswords,
140147
"Password for authenticating against the BGP peer defined with \"--peer-router-ips\".")
141148
fs.BoolVar(&s.EnablePprof, "enable-pprof", false,

0 commit comments

Comments
 (0)