Add a lower-bound for conntrack

pull/6/head
Tim Hockin 2016-09-23 14:59:15 -07:00
parent a61a1f51f3
commit 957c85a8fd
12 changed files with 3565 additions and 3472 deletions

View File

@ -85,9 +85,12 @@ func (s *ProxyServerConfig) AddFlags(fs *pflag.FlagSet) {
fs.Int32Var(&s.KubeAPIBurst, "kube-api-burst", s.KubeAPIBurst, "Burst to use while talking with kubernetes apiserver")
fs.DurationVar(&s.UDPIdleTimeout.Duration, "udp-timeout", s.UDPIdleTimeout.Duration, "How long an idle UDP connection will be kept open (e.g. '250ms', '2s'). Must be greater than 0. Only applicable for proxy-mode=userspace")
fs.Int32Var(&s.ConntrackMax, "conntrack-max", s.ConntrackMax,
"Maximum number of NAT connections to track (0 to leave as-is).")
"Maximum number of NAT connections to track (0 to leave as-is). This overrides conntrack-max-per-core and conntrack-min.")
fs.MarkDeprecated("conntrack-max", "This feature will be removed in a later release.")
fs.Int32Var(&s.ConntrackMaxPerCore, "conntrack-max-per-core", s.ConntrackMaxPerCore,
"Maximum number of NAT connections to track per CPU core (0 to leave as-is). This is only considered if conntrack-max is 0.")
"Maximum number of NAT connections to track per CPU core (0 to leave the limit as-is and ignore conntrack-min).")
fs.Int32Var(&s.ConntrackMin, "conntrack-min", s.ConntrackMin,
"Minimum number of conntrack entries to allocate, regardless of conntrack-max-per-core (set conntrack-max-per-core=0 to leave the limit as-is).")
fs.DurationVar(&s.ConntrackTCPEstablishedTimeout.Duration, "conntrack-tcp-timeout-established", s.ConntrackTCPEstablishedTimeout.Duration, "Idle timeout for established TCP connections (0 to leave as-is)")
config.DefaultFeatureGate.AddFlag(fs)
}

View File

@ -339,10 +339,18 @@ func getConntrackMax(config *options.ProxyServerConfig) (int, error) {
if config.ConntrackMaxPerCore > 0 {
return -1, fmt.Errorf("invalid config: ConntrackMax and ConntrackMaxPerCore are mutually exclusive")
}
glog.V(3).Infof("getConntrackMax: using absolute conntrax-max (deprecated)")
return int(config.ConntrackMax), nil
}
if config.ConntrackMaxPerCore > 0 {
return (int(config.ConntrackMaxPerCore) * runtime.NumCPU()), nil
floor := int(config.ConntrackMin)
scaled := int(config.ConntrackMaxPerCore) * runtime.NumCPU()
if scaled > floor {
glog.V(3).Infof("getConntrackMax: using scaled conntrax-max-per-core")
return scaled, nil
}
glog.V(3).Infof("getConntrackMax: using conntrax-min")
return floor, nil
}
return 0, nil
}

View File

@ -313,10 +313,25 @@ func TestGetConntrackMax(t *testing.T) {
},
{
config: componentconfig.KubeProxyConfiguration{
ConntrackMaxPerCore: 67890, // use this if other is 0
ConntrackMaxPerCore: 67890, // use this if Max is 0
ConntrackMin: 1, // avoid 0 default
},
expected: 67890 * ncores,
},
{
config: componentconfig.KubeProxyConfiguration{
ConntrackMaxPerCore: 1, // ensure that Min is considered
ConntrackMin: 123456,
},
expected: 123456,
},
{
config: componentconfig.KubeProxyConfiguration{
ConntrackMaxPerCore: 0, // leave system setting
ConntrackMin: 123456,
},
expected: 0,
},
}
for i, tc := range testCases {

View File

@ -88,6 +88,7 @@ configure-cbr0
configure-cloud-routes
conntrack-max
conntrack-max-per-core
conntrack-min
conntrack-tcp-timeout-established
consumer-port
consumer-service-name

File diff suppressed because it is too large Load Diff

View File

@ -66,12 +66,14 @@ type KubeProxyConfiguration struct {
// Must be greater than 0. Only applicable for proxyMode=userspace.
UDPIdleTimeout unversioned.Duration `json:"udpTimeoutMilliseconds"`
// conntrackMax is the maximum number of NAT connections to track (0 to
// leave as-is). This takes precedence over conntrackMaxPerCore.
// leave as-is). This takes precedence over conntrackMaxPerCore and conntrackMin.
ConntrackMax int32 `json:"conntrackMax"`
// conntrackMaxPerCore is the maximum number of NAT connections to track
// per CPU core (0 to leave as-is). This value is only considered if
// conntrackMax == 0.
// per CPU core (0 to leave the limit as-is and ignore conntrackMin).
ConntrackMaxPerCore int32 `json:"conntrackMaxPerCore"`
// conntrackMin is the minimum value of connect-tracking records to allocate,
// regardless of conntrackMaxPerCore (set conntrackMaxPerCore=0 to leave the limit as-is).
ConntrackMin int32 `json:"conntrackMin"`
// conntrackTCPEstablishedTimeout is how long an idle TCP connection will be kept open
// (e.g. '250ms', '2s'). Must be greater than 0.
ConntrackTCPEstablishedTimeout unversioned.Duration `json:"conntrackTCPEstablishedTimeout"`

View File

@ -89,6 +89,9 @@ func SetDefaults_KubeProxyConfiguration(obj *KubeProxyConfiguration) {
if obj.ConntrackMaxPerCore == 0 {
obj.ConntrackMaxPerCore = 32 * 1024
}
if obj.ConntrackMin == 0 {
obj.ConntrackMin = 128 * 1024
}
}
if obj.IPTablesMasqueradeBit == nil {
temp := int32(14)

View File

@ -63,12 +63,14 @@ type KubeProxyConfiguration struct {
// Must be greater than 0. Only applicable for proxyMode=userspace.
UDPIdleTimeout unversioned.Duration `json:"udpTimeoutMilliseconds"`
// conntrackMax is the maximum number of NAT connections to track (0 to
// leave as-is). This takes precedence over conntrackMaxPerCore.
// leave as-is). This takes precedence over conntrackMaxPerCore and conntrackMin.
ConntrackMax int32 `json:"conntrackMax"`
// conntrackMaxPerCore is the maximum number of NAT connections to track
// per CPU core (0 to leave as-is). This value is only considered if
// conntrackMax == 0.
// per CPU core (0 to leave the limit as-is and ignore conntrackMin).
ConntrackMaxPerCore int32 `json:"conntrackMaxPerCore"`
// conntrackMin is the minimum value of connect-tracking records to allocate,
// regardless of conntrackMaxPerCore (set conntrackMaxPerCore=0 to leave the limit as-is).
ConntrackMin int32 `json:"conntrackMin"`
// conntrackTCPEstablishedTimeout is how long an idle TCP connection will be kept open
// (e.g. '250ms', '2s'). Must be greater than 0.
ConntrackTCPEstablishedTimeout unversioned.Duration `json:"conntrackTCPEstablishedTimeout"`

View File

@ -69,6 +69,7 @@ func autoConvert_v1alpha1_KubeProxyConfiguration_To_componentconfig_KubeProxyCon
out.UDPIdleTimeout = in.UDPIdleTimeout
out.ConntrackMax = in.ConntrackMax
out.ConntrackMaxPerCore = in.ConntrackMaxPerCore
out.ConntrackMin = in.ConntrackMin
out.ConntrackTCPEstablishedTimeout = in.ConntrackTCPEstablishedTimeout
return nil
}
@ -98,6 +99,7 @@ func autoConvert_componentconfig_KubeProxyConfiguration_To_v1alpha1_KubeProxyCon
out.UDPIdleTimeout = in.UDPIdleTimeout
out.ConntrackMax = in.ConntrackMax
out.ConntrackMaxPerCore = in.ConntrackMaxPerCore
out.ConntrackMin = in.ConntrackMin
out.ConntrackTCPEstablishedTimeout = in.ConntrackTCPEstablishedTimeout
return nil
}

View File

@ -75,6 +75,7 @@ func DeepCopy_v1alpha1_KubeProxyConfiguration(in interface{}, out interface{}, c
out.UDPIdleTimeout = in.UDPIdleTimeout
out.ConntrackMax = in.ConntrackMax
out.ConntrackMaxPerCore = in.ConntrackMaxPerCore
out.ConntrackMin = in.ConntrackMin
out.ConntrackTCPEstablishedTimeout = in.ConntrackTCPEstablishedTimeout
return nil
}

View File

@ -163,6 +163,7 @@ func DeepCopy_componentconfig_KubeProxyConfiguration(in interface{}, out interfa
out.UDPIdleTimeout = in.UDPIdleTimeout
out.ConntrackMax = in.ConntrackMax
out.ConntrackMaxPerCore = in.ConntrackMaxPerCore
out.ConntrackMin = in.ConntrackMin
out.ConntrackTCPEstablishedTimeout = in.ConntrackTCPEstablishedTimeout
return nil
}

View File

@ -1968,14 +1968,21 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
"conntrackMax": {
SchemaProps: spec.SchemaProps{
Description: "conntrackMax is the maximum number of NAT connections to track (0 to leave as-is). This takes precedence over conntrackMaxPerCore.",
Description: "conntrackMax is the maximum number of NAT connections to track (0 to leave as-is). This takes precedence over conntrackMaxPerCore and conntrackMin.",
Type: []string{"integer"},
Format: "int32",
},
},
"conntrackMaxPerCore": {
SchemaProps: spec.SchemaProps{
Description: "conntrackMaxPerCore is the maximum number of NAT connections to track per CPU core (0 to leave as-is). This value is only considered if conntrackMax == 0.",
Description: "conntrackMaxPerCore is the maximum number of NAT connections to track per CPU core (0 to leave the limit as-is and ignore conntrackMin).",
Type: []string{"integer"},
Format: "int32",
},
},
"conntrackMin": {
SchemaProps: spec.SchemaProps{
Description: "conntrackMin is the minimum value of connect-tracking records to allocate, regardless of conntrackMaxPerCore (set conntrackMaxPerCore=0 to leave the limit as-is).",
Type: []string{"integer"},
Format: "int32",
},
@ -1987,7 +1994,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"TypeMeta", "bindAddress", "clusterCIDR", "healthzBindAddress", "healthzPort", "hostnameOverride", "iptablesMasqueradeBit", "iptablesSyncPeriodSeconds", "kubeconfigPath", "masqueradeAll", "master", "oomScoreAdj", "mode", "portRange", "resourceContainer", "udpTimeoutMilliseconds", "conntrackMax", "conntrackMaxPerCore", "conntrackTCPEstablishedTimeout"},
Required: []string{"TypeMeta", "bindAddress", "clusterCIDR", "healthzBindAddress", "healthzPort", "hostnameOverride", "iptablesMasqueradeBit", "iptablesSyncPeriodSeconds", "kubeconfigPath", "masqueradeAll", "master", "oomScoreAdj", "mode", "portRange", "resourceContainer", "udpTimeoutMilliseconds", "conntrackMax", "conntrackMaxPerCore", "conntrackMin", "conntrackTCPEstablishedTimeout"},
},
},
Dependencies: []string{
@ -13377,14 +13384,21 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
"conntrackMax": {
SchemaProps: spec.SchemaProps{
Description: "conntrackMax is the maximum number of NAT connections to track (0 to leave as-is). This takes precedence over conntrackMaxPerCore.",
Description: "conntrackMax is the maximum number of NAT connections to track (0 to leave as-is). This takes precedence over conntrackMaxPerCore and conntrackMin.",
Type: []string{"integer"},
Format: "int32",
},
},
"conntrackMaxPerCore": {
SchemaProps: spec.SchemaProps{
Description: "conntrackMaxPerCore is the maximum number of NAT connections to track per CPU core (0 to leave as-is). This value is only considered if conntrackMax == 0.",
Description: "conntrackMaxPerCore is the maximum number of NAT connections to track per CPU core (0 to leave the limit as-is and ignore conntrackMin).",
Type: []string{"integer"},
Format: "int32",
},
},
"conntrackMin": {
SchemaProps: spec.SchemaProps{
Description: "conntrackMin is the minimum value of connect-tracking records to allocate, regardless of conntrackMaxPerCore (set conntrackMaxPerCore=0 to leave the limit as-is).",
Type: []string{"integer"},
Format: "int32",
},
@ -13396,7 +13410,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"TypeMeta", "bindAddress", "clusterCIDR", "healthzBindAddress", "healthzPort", "hostnameOverride", "iptablesMasqueradeBit", "iptablesSyncPeriodSeconds", "kubeconfigPath", "masqueradeAll", "master", "oomScoreAdj", "mode", "portRange", "resourceContainer", "udpTimeoutMilliseconds", "conntrackMax", "conntrackMaxPerCore", "conntrackTCPEstablishedTimeout"},
Required: []string{"TypeMeta", "bindAddress", "clusterCIDR", "healthzBindAddress", "healthzPort", "hostnameOverride", "iptablesMasqueradeBit", "iptablesSyncPeriodSeconds", "kubeconfigPath", "masqueradeAll", "master", "oomScoreAdj", "mode", "portRange", "resourceContainer", "udpTimeoutMilliseconds", "conntrackMax", "conntrackMaxPerCore", "conntrackMin", "conntrackTCPEstablishedTimeout"},
},
},
Dependencies: []string{