diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 494a31b6b2c..03c5c25191d 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -434,7 +434,13 @@ func NewMainKubelet( imageBackOff, serializeImagePulls, enableCustomMetrics, - klet.hairpinMode == componentconfig.HairpinVeth, + // If using "kubenet", the Kubernetes network plugin that wraps + // CNI's bridge plugin, it knows how to set the hairpin veth flag + // so we tell the container runtime to back away from setting it. + // If the kubelet is started with any other plugin we can't be + // sure it handles the hairpin case so we instruct the docker + // runtime to set the flag instead. + klet.hairpinMode == componentconfig.HairpinVeth && networkPluginName != "kubenet", seccompProfileRoot, containerRuntimeOptions..., ) diff --git a/pkg/kubelet/network/kubenet/kubenet_linux.go b/pkg/kubelet/network/kubenet/kubenet_linux.go index b7de8e68ae3..a1c86e8dcea 100644 --- a/pkg/kubelet/network/kubenet/kubenet_linux.go +++ b/pkg/kubelet/network/kubenet/kubenet_linux.go @@ -186,6 +186,7 @@ const NET_CONFIG_TEMPLATE = `{ "addIf": "%s", "isGateway": true, "ipMasq": false, + "hairpin": "%t", "ipam": { "type": "host-local", "subnet": "%s", @@ -218,10 +219,11 @@ func (plugin *kubenetNetworkPlugin) Event(name string, details map[string]interf glog.V(5).Infof("PodCIDR is set to %q", podCIDR) _, cidr, err := net.ParseCIDR(podCIDR) if err == nil { + setHairpin := plugin.hairpinMode == componentconfig.HairpinVeth // Set bridge address to first address in IPNet cidr.IP.To4()[3] += 1 - json := fmt.Sprintf(NET_CONFIG_TEMPLATE, BridgeName, plugin.MTU, network.DefaultInterfaceName, podCIDR, cidr.IP.String()) + json := fmt.Sprintf(NET_CONFIG_TEMPLATE, BridgeName, plugin.MTU, network.DefaultInterfaceName, setHairpin, podCIDR, cidr.IP.String()) glog.V(2).Infof("CNI network config set to %v", json) plugin.netConfig, err = libcni.ConfFromBytes([]byte(json)) if err == nil {