k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/proxy/apis/config/types.go (about) 1 /* 2 Copyright 2015 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package config 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 componentbaseconfig "k8s.io/component-base/config" 22 logsapi "k8s.io/component-base/logs/api/v1" 23 ) 24 25 // KubeProxyIPTablesConfiguration contains iptables-related configuration 26 // details for the Kubernetes proxy server. 27 type KubeProxyIPTablesConfiguration struct { 28 // masqueradeBit is the bit of the iptables fwmark space to use for SNAT if using 29 // the iptables or ipvs proxy mode. Values must be within the range [0, 31]. 30 MasqueradeBit *int32 31 // masqueradeAll tells kube-proxy to SNAT all traffic sent to Service cluster IPs, 32 // when using the iptables or ipvs proxy mode. This may be required with some CNI 33 // plugins. 34 MasqueradeAll bool 35 // localhostNodePorts, if false, tells kube-proxy to disable the legacy behavior 36 // of allowing NodePort services to be accessed via localhost. (Applies only to 37 // iptables mode and IPv4; localhost NodePorts are never allowed with other proxy 38 // modes or with IPv6.) 39 LocalhostNodePorts *bool 40 // syncPeriod is an interval (e.g. '5s', '1m', '2h22m') indicating how frequently 41 // various re-synchronizing and cleanup operations are performed. Must be greater 42 // than 0. 43 SyncPeriod metav1.Duration 44 // minSyncPeriod is the minimum period between iptables rule resyncs (e.g. '5s', 45 // '1m', '2h22m'). A value of 0 means every Service or EndpointSlice change will 46 // result in an immediate iptables resync. 47 MinSyncPeriod metav1.Duration 48 } 49 50 // KubeProxyIPVSConfiguration contains ipvs-related configuration 51 // details for the Kubernetes proxy server. 52 type KubeProxyIPVSConfiguration struct { 53 // syncPeriod is an interval (e.g. '5s', '1m', '2h22m') indicating how frequently 54 // various re-synchronizing and cleanup operations are performed. Must be greater 55 // than 0. 56 SyncPeriod metav1.Duration 57 // minSyncPeriod is the minimum period between IPVS rule resyncs (e.g. '5s', '1m', 58 // '2h22m'). A value of 0 means every Service or EndpointSlice change will result 59 // in an immediate IPVS resync. 60 MinSyncPeriod metav1.Duration 61 // scheduler is the IPVS scheduler to use 62 Scheduler string 63 // excludeCIDRs is a list of CIDRs which the ipvs proxier should not touch 64 // when cleaning up ipvs services. 65 ExcludeCIDRs []string 66 // strictARP configures arp_ignore and arp_announce to avoid answering ARP queries 67 // from kube-ipvs0 interface 68 StrictARP bool 69 // tcpTimeout is the timeout value used for idle IPVS TCP sessions. 70 // The default value is 0, which preserves the current timeout value on the system. 71 TCPTimeout metav1.Duration 72 // tcpFinTimeout is the timeout value used for IPVS TCP sessions after receiving a FIN. 73 // The default value is 0, which preserves the current timeout value on the system. 74 TCPFinTimeout metav1.Duration 75 // udpTimeout is the timeout value used for IPVS UDP packets. 76 // The default value is 0, which preserves the current timeout value on the system. 77 UDPTimeout metav1.Duration 78 } 79 80 // KubeProxyNFTablesConfiguration contains nftables-related configuration 81 // details for the Kubernetes proxy server. 82 type KubeProxyNFTablesConfiguration struct { 83 // masqueradeBit is the bit of the iptables fwmark space to use for SNAT if using 84 // the nftables proxy mode. Values must be within the range [0, 31]. 85 MasqueradeBit *int32 86 // masqueradeAll tells kube-proxy to SNAT all traffic sent to Service cluster IPs, 87 // when using the nftables mode. This may be required with some CNI plugins. 88 MasqueradeAll bool 89 // syncPeriod is an interval (e.g. '5s', '1m', '2h22m') indicating how frequently 90 // various re-synchronizing and cleanup operations are performed. Must be greater 91 // than 0. 92 SyncPeriod metav1.Duration 93 // minSyncPeriod is the minimum period between iptables rule resyncs (e.g. '5s', 94 // '1m', '2h22m'). A value of 0 means every Service or EndpointSlice change will 95 // result in an immediate iptables resync. 96 MinSyncPeriod metav1.Duration 97 } 98 99 // KubeProxyConntrackConfiguration contains conntrack settings for 100 // the Kubernetes proxy server. 101 type KubeProxyConntrackConfiguration struct { 102 // maxPerCore is the maximum number of NAT connections to track 103 // per CPU core (0 to leave the limit as-is and ignore min). 104 MaxPerCore *int32 105 // min is the minimum value of connect-tracking records to allocate, 106 // regardless of maxPerCore (set maxPerCore=0 to leave the limit as-is). 107 Min *int32 108 // tcpEstablishedTimeout is how long an idle TCP connection will be kept open 109 // (e.g. '2s'). Must be greater than 0 to set. 110 TCPEstablishedTimeout *metav1.Duration 111 // tcpCloseWaitTimeout is how long an idle conntrack entry 112 // in CLOSE_WAIT state will remain in the conntrack 113 // table. (e.g. '60s'). Must be greater than 0 to set. 114 TCPCloseWaitTimeout *metav1.Duration 115 // tcpBeLiberal, if true, kube-proxy will configure conntrack 116 // to run in liberal mode for TCP connections and packets with 117 // out-of-window sequence numbers won't be marked INVALID. 118 TCPBeLiberal bool 119 // udpTimeout is how long an idle UDP conntrack entry in 120 // UNREPLIED state will remain in the conntrack table 121 // (e.g. '30s'). Must be greater than 0 to set. 122 UDPTimeout metav1.Duration 123 // udpStreamTimeout is how long an idle UDP conntrack entry in 124 // ASSURED state will remain in the conntrack table 125 // (e.g. '300s'). Must be greater than 0 to set. 126 UDPStreamTimeout metav1.Duration 127 } 128 129 // KubeProxyWinkernelConfiguration contains Windows/HNS settings for 130 // the Kubernetes proxy server. 131 type KubeProxyWinkernelConfiguration struct { 132 // networkName is the name of the network kube-proxy will use 133 // to create endpoints and policies 134 NetworkName string 135 // sourceVip is the IP address of the source VIP endpoint used for 136 // NAT when loadbalancing 137 SourceVip string 138 // enableDSR tells kube-proxy whether HNS policies should be created 139 // with DSR 140 EnableDSR bool 141 // rootHnsEndpointName is the name of hnsendpoint that is attached to 142 // l2bridge for root network namespace 143 RootHnsEndpointName string 144 // forwardHealthCheckVip forwards service VIP for health check port on 145 // Windows 146 ForwardHealthCheckVip bool 147 } 148 149 // DetectLocalConfiguration contains optional settings related to DetectLocalMode option 150 type DetectLocalConfiguration struct { 151 // bridgeInterface is a bridge interface name. When DetectLocalMode is set to 152 // LocalModeBridgeInterface, kube-proxy will consider traffic to be local if 153 // it originates from this bridge. 154 BridgeInterface string 155 // interfaceNamePrefix is an interface name prefix. When DetectLocalMode is set to 156 // LocalModeInterfaceNamePrefix, kube-proxy will consider traffic to be local if 157 // it originates from any interface whose name begins with this prefix. 158 InterfaceNamePrefix string 159 } 160 161 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 162 163 // KubeProxyConfiguration contains everything necessary to configure the 164 // Kubernetes proxy server. 165 type KubeProxyConfiguration struct { 166 metav1.TypeMeta 167 168 // featureGates is a map of feature names to bools that enable or disable alpha/experimental features. 169 FeatureGates map[string]bool 170 171 // clientConnection specifies the kubeconfig file and client connection settings for the proxy 172 // server to use when communicating with the apiserver. 173 ClientConnection componentbaseconfig.ClientConnectionConfiguration 174 // logging specifies the options of logging. 175 // Refer to [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) 176 // for more information. 177 Logging logsapi.LoggingConfiguration 178 179 // hostnameOverride, if non-empty, will be used as the name of the Node that 180 // kube-proxy is running on. If unset, the node name is assumed to be the same as 181 // the node's hostname. 182 HostnameOverride string 183 // bindAddress can be used to override kube-proxy's idea of what its node's 184 // primary IP is. Note that the name is a historical artifact, and kube-proxy does 185 // not actually bind any sockets to this IP. 186 BindAddress string 187 // healthzBindAddress is the IP address and port for the health check server to 188 // serve on, defaulting to "0.0.0.0:10256" (if bindAddress is unset or IPv4), or 189 // "[::]:10256" (if bindAddress is IPv6). 190 HealthzBindAddress string 191 // metricsBindAddress is the IP address and port for the metrics server to serve 192 // on, defaulting to "127.0.0.1:10249" (if bindAddress is unset or IPv4), or 193 // "[::1]:10249" (if bindAddress is IPv6). (Set to "0.0.0.0:10249" / "[::]:10249" 194 // to bind on all interfaces.) 195 MetricsBindAddress string 196 // bindAddressHardFail, if true, tells kube-proxy to treat failure to bind to a 197 // port as fatal and exit 198 BindAddressHardFail bool 199 // enableProfiling enables profiling via web interface on /debug/pprof handler. 200 // Profiling handlers will be handled by metrics server. 201 EnableProfiling bool 202 // showHiddenMetricsForVersion is the version for which you want to show hidden metrics. 203 ShowHiddenMetricsForVersion string 204 205 // mode specifies which proxy mode to use. 206 Mode ProxyMode 207 // iptables contains iptables-related configuration options. 208 IPTables KubeProxyIPTablesConfiguration 209 // ipvs contains ipvs-related configuration options. 210 IPVS KubeProxyIPVSConfiguration 211 // winkernel contains winkernel-related configuration options. 212 Winkernel KubeProxyWinkernelConfiguration 213 // nftables contains nftables-related configuration options. 214 NFTables KubeProxyNFTablesConfiguration 215 216 // detectLocalMode determines mode to use for detecting local traffic, defaults to LocalModeClusterCIDR 217 DetectLocalMode LocalMode 218 // detectLocal contains optional configuration settings related to DetectLocalMode. 219 DetectLocal DetectLocalConfiguration 220 // clusterCIDR is the CIDR range of the pods in the cluster. (For dual-stack 221 // clusters, this can be a comma-separated dual-stack pair of CIDR ranges.). When 222 // DetectLocalMode is set to LocalModeClusterCIDR, kube-proxy will consider 223 // traffic to be local if its source IP is in this range. (Otherwise it is not 224 // used.) 225 ClusterCIDR string 226 227 // nodePortAddresses is a list of CIDR ranges that contain valid node IPs, or 228 // alternatively, the single string 'primary'. If set to a list of CIDRs, 229 // connections to NodePort services will only be accepted on node IPs in one of 230 // the indicated ranges. If set to 'primary', NodePort services will only be 231 // accepted on the node's primary IPv4 and/or IPv6 address according to the Node 232 // object. If unset, NodePort connections will be accepted on all local IPs. 233 NodePortAddresses []string 234 235 // oomScoreAdj is the oom-score-adj value for kube-proxy process. Values must be within 236 // the range [-1000, 1000] 237 OOMScoreAdj *int32 238 // conntrack contains conntrack-related configuration options. 239 Conntrack KubeProxyConntrackConfiguration 240 // configSyncPeriod is how often configuration from the apiserver is refreshed. Must be greater 241 // than 0. 242 ConfigSyncPeriod metav1.Duration 243 244 // portRange was previously used to configure the userspace proxy, but is now unused. 245 PortRange string 246 } 247 248 // ProxyMode represents modes used by the Kubernetes proxy server. 249 // 250 // Currently, three modes of proxy are available on Linux platforms: 'iptables', 'ipvs', 251 // and 'nftables'. One mode of proxy is available on Windows platforms: 'kernelspace'. 252 // 253 // If the proxy mode is unspecified, the best-available proxy mode will be used (currently this 254 // is `iptables` on Linux and `kernelspace` on Windows). If the selected proxy mode cannot be 255 // used (due to lack of kernel support, missing userspace components, etc) then kube-proxy 256 // will exit with an error. 257 type ProxyMode string 258 259 const ( 260 ProxyModeIPTables ProxyMode = "iptables" 261 ProxyModeIPVS ProxyMode = "ipvs" 262 ProxyModeNFTables ProxyMode = "nftables" 263 ProxyModeKernelspace ProxyMode = "kernelspace" 264 ) 265 266 func (m *ProxyMode) Set(s string) error { 267 *m = ProxyMode(s) 268 return nil 269 } 270 271 func (m *ProxyMode) String() string { 272 if m != nil { 273 return string(*m) 274 } 275 return "" 276 } 277 278 func (m *ProxyMode) Type() string { 279 return "ProxyMode" 280 } 281 282 // LocalMode represents modes to detect local traffic from the node 283 type LocalMode string 284 285 // Currently supported modes for LocalMode 286 const ( 287 LocalModeClusterCIDR LocalMode = "ClusterCIDR" 288 LocalModeNodeCIDR LocalMode = "NodeCIDR" 289 LocalModeBridgeInterface LocalMode = "BridgeInterface" 290 LocalModeInterfaceNamePrefix LocalMode = "InterfaceNamePrefix" 291 ) 292 293 func (m *LocalMode) Set(s string) error { 294 *m = LocalMode(s) 295 return nil 296 } 297 298 func (m *LocalMode) String() string { 299 if m != nil { 300 return string(*m) 301 } 302 return "" 303 } 304 305 func (m *LocalMode) Type() string { 306 return "LocalMode" 307 } 308 309 // NodePortAddressesPrimary is a special value for NodePortAddresses indicating that it 310 // should only use the primary node IPs. 311 const NodePortAddressesPrimary string = "primary"