Commit 63602348 authored by k8s-merge-robot's avatar k8s-merge-robot Committed by GitHub

Merge pull request #29009 from bboreham/hairpin-via-cni

Automatic merge from submit-queue Use the CNI bridge plugin to set hairpin mode Following up this part of #23711: > I'd like to wait until containernetworking/cni#175 lands and then just pass the request through to CNI. The code here just * passes the required setting down from kubenet to CNI * disables `DockerManager` from doing hairpin-veth, if kubenet is in use Note to test you need a very recent version of the CNI `bridge` plugin; the one brought in by #28799 should be OK. Also relates to https://github.com/kubernetes/kubernetes/issues/19766#issuecomment-232722864
parents 6ae6450a f21d2dde
...@@ -434,7 +434,13 @@ func NewMainKubelet( ...@@ -434,7 +434,13 @@ func NewMainKubelet(
imageBackOff, imageBackOff,
serializeImagePulls, serializeImagePulls,
enableCustomMetrics, 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, seccompProfileRoot,
containerRuntimeOptions..., containerRuntimeOptions...,
) )
......
...@@ -186,6 +186,7 @@ const NET_CONFIG_TEMPLATE = `{ ...@@ -186,6 +186,7 @@ const NET_CONFIG_TEMPLATE = `{
"addIf": "%s", "addIf": "%s",
"isGateway": true, "isGateway": true,
"ipMasq": false, "ipMasq": false,
"hairpin": "%t",
"ipam": { "ipam": {
"type": "host-local", "type": "host-local",
"subnet": "%s", "subnet": "%s",
...@@ -218,10 +219,11 @@ func (plugin *kubenetNetworkPlugin) Event(name string, details map[string]interf ...@@ -218,10 +219,11 @@ func (plugin *kubenetNetworkPlugin) Event(name string, details map[string]interf
glog.V(5).Infof("PodCIDR is set to %q", podCIDR) glog.V(5).Infof("PodCIDR is set to %q", podCIDR)
_, cidr, err := net.ParseCIDR(podCIDR) _, cidr, err := net.ParseCIDR(podCIDR)
if err == nil { if err == nil {
setHairpin := plugin.hairpinMode == componentconfig.HairpinVeth
// Set bridge address to first address in IPNet // Set bridge address to first address in IPNet
cidr.IP.To4()[3] += 1 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) glog.V(2).Infof("CNI network config set to %v", json)
plugin.netConfig, err = libcni.ConfFromBytes([]byte(json)) plugin.netConfig, err = libcni.ConfFromBytes([]byte(json))
if err == nil { if err == nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment