Skip to content

Commit

Permalink
addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
murali-reddy authored and aauren committed Oct 2, 2020
1 parent 947bb24 commit 7904b7c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
25 changes: 25 additions & 0 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Usage of kube-router:
--advertise-external-ip Add External IP of service to the RIB so that it gets advertised to the BGP peers.
--advertise-loadbalancer-ip Add LoadbBalancer IP of service status as set by the LB provider to the RIB so that it gets advertised to the BGP peers.
--advertise-pod-cidr Add Node's POD cidr to the RIB so that it gets advertised to the BGP peers. (default true)
--auto-mtu Auto detect and set the largest possible MTU for pod interfaces. (default true)
--bgp-graceful-restart Enables the BGP Graceful Restart capability so that routes are preserved on unexpected restarts
--bgp-graceful-restart-deferral-time duration BGP Graceful restart deferral time according to RFC4724 4.1, maximum 18h. (default 6m0s)
--bgp-graceful-restart-time duration BGP Graceful restart time according to RFC4724 3, maximum 4095s. (default 1m30s)
Expand Down Expand Up @@ -309,6 +310,30 @@ the fallback period is 30 seconds and can be adjusted with `--ipvs-graceful-peri

graceful termination works in such a way that when kube-router receives a delete endpoint notification for a service it's weight is adjusted to 0 before getting deleted after he termination grace period has passed or the Active & Inactive connections goes down to 0.

## MTU

The maximum transmission unit (MTU) determines the largest packet size that can be transmitted through your network. MTU for the pod interfaces should be set appropriately to prevent fragmentation and packet drops thereby achieving maximum performance. If you set `auto-mtu` to true kube-router will determine right MTU for both `kube-bridge` and pod interfaces. If you set `auto-mtu` to false kube-router will not attempt to configure MTU. However you can choose the right MTU and set in the `cni-conf.json` section of the `10-kuberouter.conflist` in the kube-router [daemonsets](../daemonset/). For e.g.

```
cni-conf.json: |
{
"cniVersion":"0.3.0",
"name":"mynet",
"plugins":[
{
"name":"kubernetes",
"type":"bridge",
"mtu": 1400,
"bridge":"kube-bridge",
"isDefaultGateway":true,
"ipam":{
"type":"host-local"
}
}
]
}
```

## BGP configuration

[Configuring BGP Peers](bgp.md)
Expand Down
31 changes: 25 additions & 6 deletions pkg/controllers/routing/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type NetworkRoutingController struct {
advertiseExternalIP bool
advertiseLoadBalancerIP bool
advertisePodCidr bool
autoMTU bool
defaultNodeAsnNumber uint32
nodeAsnNumber uint32
globalPeerRouters []*gobgpapi.Peer
Expand Down Expand Up @@ -190,15 +191,15 @@ func (nrc *NetworkRoutingController) Run(healthChan chan<- *healthcheck.Controll
}

// create 'kube-bridge' interface to which pods will be connected
_, err = netlink.LinkByName("kube-bridge")
kubeBridgeIf, err := netlink.LinkByName("kube-bridge")
if err != nil && err.Error() == IfaceNotFound {
linkAttrs := netlink.NewLinkAttrs()
linkAttrs.Name = "kube-bridge"
bridge := &netlink.Bridge{LinkAttrs: linkAttrs}
if err = netlink.LinkAdd(bridge); err != nil {
glog.Errorf("Failed to create `kube-router` bridge due to %s. Will be created by CNI bridge plugin when pod is launched.", err.Error())
}
kubeBridgeIf, err := netlink.LinkByName("kube-bridge")
kubeBridgeIf, err = netlink.LinkByName("kube-bridge")
if err != nil {
glog.Errorf("Failed to find created `kube-router` bridge due to %s. Will be created by CNI bridge plugin when pod is launched.", err.Error())
}
Expand All @@ -208,6 +209,21 @@ func (nrc *NetworkRoutingController) Run(healthChan chan<- *healthcheck.Controll
}
}

if nrc.autoMTU {
mtu, err := getMTUFromNodeIP(nrc.nodeIP, nrc.enableOverlays)
if err != nil {
glog.Errorf("Failed to find MTU for node IP: %s for intelligently setting the kube-bridge MTU due to %s.", nrc.nodeIP, err.Error())
}
if mtu > 0 {
glog.Infof("Setting MTU of kube-bridge interface to: %d", mtu)
err = netlink.LinkSetMTU(kubeBridgeIf, mtu)
if err != nil {
glog.Errorf("Failed to set MTU for kube-bridge interface due to: %s", err.Error())
}
} else {
glog.Infof("Not setting MTU of kube-bridge interface")
}
}
// enable netfilter for the bridge
if _, err := exec.Command("modprobe", "br_netfilter").CombinedOutput(); err != nil {
glog.Errorf("Failed to enable netfilter for bridge. Network policies and service proxy may not work: %s", err.Error())
Expand Down Expand Up @@ -343,14 +359,16 @@ func (nrc *NetworkRoutingController) updateCNIConfig() {
}
}

err = nrc.autoConfigureMTU()
if err != nil {
glog.Fatalf("Failed to auto-configure MTU: %s", err.Error())
if nrc.autoMTU {
err = nrc.autoConfigureMTU()
if err != nil {
glog.Fatalf("Failed to auto-configure MTU: %s", err.Error())
}
}
}

func (nrc *NetworkRoutingController) autoConfigureMTU() error {
mtu, err := getMTUFromNodeIP(nrc.nodeIP)
mtu, err := getMTUFromNodeIP(nrc.nodeIP, nrc.enableOverlays)
if err != nil {
return fmt.Errorf("failed to generate MTU: %s", err.Error())
}
Expand Down Expand Up @@ -1077,6 +1095,7 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
nrc.advertiseExternalIP = kubeRouterConfig.AdvertiseExternalIP
nrc.advertiseLoadBalancerIP = kubeRouterConfig.AdvertiseLoadBalancerIP
nrc.advertisePodCidr = kubeRouterConfig.AdvertiseNodePodCidr
nrc.autoMTU = kubeRouterConfig.AutoMTU
nrc.enableOverlays = kubeRouterConfig.EnableOverlay
nrc.overlayType = kubeRouterConfig.OverlayType

Expand Down
9 changes: 6 additions & 3 deletions pkg/controllers/routing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func getNodeSubnet(nodeIP net.IP) (net.IPNet, string, error) {
return net.IPNet{}, "", errors.New("Failed to find interface with specified node ip")
}

func getMTUFromNodeIP(nodeIP net.IP) (int, error) {
func getMTUFromNodeIP(nodeIP net.IP, overlayEnabled bool) (int, error) {
links, err := netlink.LinkList()
if err != nil {
return 0, errors.New("Failed to get list of links")
Expand All @@ -132,8 +132,11 @@ func getMTUFromNodeIP(nodeIP net.IP) (int, error) {
}
for _, addr := range addresses {
if addr.IPNet.IP.Equal(nodeIP) {
lintMTU := link.Attrs().MTU
return lintMTU - 20, nil // -20 to accommodate IPIP header
linkMTU := link.Attrs().MTU
if overlayEnabled {
return linkMTU - 20, nil // -20 to accommodate IPIP header
}
return linkMTU, nil
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type KubeRouterConfig struct {
AdvertiseExternalIP bool
AdvertiseLoadBalancerIP bool
AdvertiseNodePodCidr bool
AutoMTU bool
BGPGracefulRestart bool
BGPGracefulRestartDeferralTime time.Duration
BGPGracefulRestartTime time.Duration
Expand Down Expand Up @@ -95,6 +96,8 @@ func (s *KubeRouterConfig) AddFlags(fs *pflag.FlagSet) {
"Add LoadbBalancer IP of service status as set by the LB provider to the RIB so that it gets advertised to the BGP peers.")
fs.BoolVar(&s.AdvertiseNodePodCidr, "advertise-pod-cidr", true,
"Add Node's POD cidr to the RIB so that it gets advertised to the BGP peers.")
fs.BoolVar(&s.AutoMTU, "auto-mtu", true,
"Auto detect and set the largest possible MTU for pod interfaces.")
fs.BoolVar(&s.BGPGracefulRestart, "bgp-graceful-restart", false,
"Enables the BGP Graceful Restart capability so that routes are preserved on unexpected restarts")
fs.DurationVar(&s.BGPGracefulRestartDeferralTime, "bgp-graceful-restart-deferral-time", s.BGPGracefulRestartDeferralTime,
Expand Down

0 comments on commit 7904b7c

Please sign in to comment.