diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index ca3ac4031e7..11a210ce2cb 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -805,6 +805,10 @@ function construct-linux-kubelet-flags { } # Sets KUBELET_ARGS with the kubelet flags for Windows nodes. +# Note that to configure flags with explicit empty string values, we can't escape +# double-quotes, because they still break sc.exe after expansion in the +# binPath parameter, and single-quotes get parsed as characters instead of +# string delimiters. function construct-windows-kubelet-flags { local flags="$(construct-common-kubelet-flags)" @@ -868,11 +872,8 @@ function construct-windows-kubelet-flags { # actually log to the file flags+=" --logtostderr=false" - # Configure flags with explicit empty string values. We can't escape - # double-quotes, because they still break sc.exe after expansion in the - # binPath parameter, and single-quotes get parsed as characters instead of - # string delimiters. - flags+=" --resolv-conf=" + # Configure the file path for host dns configuration + flags+=" --resolv-conf=${WINDOWS_CNI_CONFIG_DIR}\hostdns.conf" # Both --cgroups-per-qos and --enforce-node-allocatable should be disabled on # windows; the latter requires the former to be enabled to work. diff --git a/cluster/gce/windows/configure.ps1 b/cluster/gce/windows/configure.ps1 index 800e9e5f3be..f1835ce9d57 100644 --- a/cluster/gce/windows/configure.ps1 +++ b/cluster/gce/windows/configure.ps1 @@ -126,6 +126,7 @@ try { Set-PodCidr Configure-HostNetworkingService Configure-CniNetworking + Configure-HostDnsConf Configure-GcePdTools Configure-Kubelet diff --git a/cluster/gce/windows/k8s-node-setup.psm1 b/cluster/gce/windows/k8s-node-setup.psm1 index 69709cb8879..399999adf51 100644 --- a/cluster/gce/windows/k8s-node-setup.psm1 +++ b/cluster/gce/windows/k8s-node-setup.psm1 @@ -857,7 +857,8 @@ function Configure-CniNetworking { "name": "l2bridge", "type": "win-bridge", "capabilities": { - "portMappings": true + "portMappings": true, + "dns": true }, "ipam": { "type": "host-local", @@ -913,6 +914,28 @@ function Configure-CniNetworking { Log-Output "CNI config:`n$(Get-Content -Raw ${l2bridge_conf})" } +# Obtain the host dns conf and save it to a file so that kubelet/CNI +# can use it to configure dns suffix search list for pods. +# The value of DNS server is ignored right now because the pod will +# always only use cluster DNS service, but for consistency, we still +# parsed them here in the same format as Linux resolv.conf. +# This function must be called after Configure-HostNetworkingService. +function Configure-HostDnsConf { + $net_adapter = Get_MgmtNetAdapter + $server_ips = (Get-DnsClientServerAddress ` + -InterfaceAlias ${net_adapter}.Name).ServerAddresses + $search_list = (Get-DnsClient).ConnectionSpecificSuffixSearchList + $conf = "" + ForEach ($ip in $server_ips) { + $conf = $conf + "nameserver $ip`r`n" + } + $conf = $conf + "search $search_list" + $hostdns_conf = "${env:CNI_CONFIG_DIR}\hostdns.conf" + New-Item -Force -ItemType file ${hostdns_conf} | Out-Null + Set-Content ${hostdns_conf} $conf + Log-Output "HOST dns conf:`n$(Get-Content -Raw ${hostdns_conf})" +} + # Fetches the kubelet config from the instance metadata and puts it at # $env:KUBELET_CONFIG. function Configure-Kubelet {