diff --git a/cmd/kubelet/app/options/options.go b/cmd/kubelet/app/options/options.go index b87cd735659..fea488e00ab 100644 --- a/cmd/kubelet/app/options/options.go +++ b/cmd/kubelet/app/options/options.go @@ -292,7 +292,7 @@ func (f *KubeletFlags) AddFlags(mainfs *pflag.FlagSet) { fs.StringVar(&f.HostnameOverride, "hostname-override", f.HostnameOverride, "If non-empty, will use this string as identification instead of the actual hostname. If --cloud-provider is set, the cloud provider determines the name of the node (consult cloud provider documentation to determine if and how the hostname is used).") - fs.StringVar(&f.NodeIP, "node-ip", f.NodeIP, "IP address (or comma-separated dual-stack IP addresses) of the node. If unset, kubelet will use the node's default IPv4 address, if any, or its default IPv6 address if it has no IPv4 addresses. You can pass '::' to make it prefer the default IPv6 address rather than the default IPv4 address.") + fs.StringVar(&f.NodeIP, "node-ip", f.NodeIP, "IP address (or comma-separated dual-stack IP addresses) of the node. If unset, kubelet will use the node's default IPv4 address, if any, or its default IPv6 address if it has no IPv4 addresses. You can pass '::' to make it prefer the default IPv6 address rather than the default IPv4 address. If cloud-provider is set to external, this flag will help to bootstrap the node with the corresponding IP.") fs.StringVar(&f.CertDirectory, "cert-dir", f.CertDirectory, "The directory where the TLS certs are located. "+ "If --tls-cert-file and --tls-private-key-file are provided, this flag will be ignored.") diff --git a/pkg/kubelet/nodestatus/setters.go b/pkg/kubelet/nodestatus/setters.go index 19bb6ce7295..6e97651413f 100644 --- a/pkg/kubelet/nodestatus/setters.go +++ b/pkg/kubelet/nodestatus/setters.go @@ -129,12 +129,15 @@ func NodeAddress(nodeIPs []net.IP, // typically Kubelet.nodeIPs if len(node.Status.Addresses) > 0 { return nil } - // If nodeIPs are not specified wait for the external cloud-provider to set the node addresses. + // If nodeIPs are not set wait for the external cloud-provider to set the node addresses. + // If the nodeIP is the unspecified address 0.0.0.0 or ::, then use the IP of the default gateway of + // the corresponding IP family to bootstrap the node until the out-of-tree provider overrides it later. + // xref: https://github.com/kubernetes/kubernetes/issues/125348 // Otherwise uses them on the assumption that the installer/administrator has the previous knowledge // required to ensure the external cloud provider will use the same addresses to avoid the issues explained // in https://github.com/kubernetes/kubernetes/issues/120720. // We are already hinting the external cloud provider via the annotation AnnotationAlphaProvidedIPAddr. - if !nodeIPSpecified { + if nodeIP == nil { node.Status.Addresses = []v1.NodeAddress{ {Type: v1.NodeHostName, Address: hostname}, }