Skip to content

Commit 397ed0e

Browse files
authored
Merge pull request kubernetes#82314 from lzang/master
Add dns capability to GCE window cluster
2 parents 836b901 + 2a3ab18 commit 397ed0e

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

cluster/gce/util.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,10 @@ function construct-linux-kubelet-flags {
805805
}
806806

807807
# Sets KUBELET_ARGS with the kubelet flags for Windows nodes.
808+
# Note that to configure flags with explicit empty string values, we can't escape
809+
# double-quotes, because they still break sc.exe after expansion in the
810+
# binPath parameter, and single-quotes get parsed as characters instead of
811+
# string delimiters.
808812
function construct-windows-kubelet-flags {
809813
local flags="$(construct-common-kubelet-flags)"
810814

@@ -868,11 +872,8 @@ function construct-windows-kubelet-flags {
868872
# actually log to the file
869873
flags+=" --logtostderr=false"
870874

871-
# Configure flags with explicit empty string values. We can't escape
872-
# double-quotes, because they still break sc.exe after expansion in the
873-
# binPath parameter, and single-quotes get parsed as characters instead of
874-
# string delimiters.
875-
flags+=" --resolv-conf="
875+
# Configure the file path for host dns configuration
876+
flags+=" --resolv-conf=${WINDOWS_CNI_CONFIG_DIR}\hostdns.conf"
876877

877878
# Both --cgroups-per-qos and --enforce-node-allocatable should be disabled on
878879
# windows; the latter requires the former to be enabled to work.

cluster/gce/windows/configure.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ try {
148148
Set-PodCidr
149149
Configure-HostNetworkingService
150150
Configure-CniNetworking
151+
Configure-HostDnsConf
151152
Configure-GcePdTools
152153
Configure-Kubelet
153154

cluster/gce/windows/k8s-node-setup.psm1

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@ function Configure-CniNetworking {
857857
"name": "l2bridge",
858858
"type": "win-bridge",
859859
"capabilities": {
860-
"portMappings": true
860+
"portMappings": true,
861+
"dns": true
861862
},
862863
"ipam": {
863864
"type": "host-local",
@@ -913,6 +914,28 @@ function Configure-CniNetworking {
913914
Log-Output "CNI config:`n$(Get-Content -Raw ${l2bridge_conf})"
914915
}
915916

917+
# Obtain the host dns conf and save it to a file so that kubelet/CNI
918+
# can use it to configure dns suffix search list for pods.
919+
# The value of DNS server is ignored right now because the pod will
920+
# always only use cluster DNS service, but for consistency, we still
921+
# parsed them here in the same format as Linux resolv.conf.
922+
# This function must be called after Configure-HostNetworkingService.
923+
function Configure-HostDnsConf {
924+
$net_adapter = Get_MgmtNetAdapter
925+
$server_ips = (Get-DnsClientServerAddress `
926+
-InterfaceAlias ${net_adapter}.Name).ServerAddresses
927+
$search_list = (Get-DnsClient).ConnectionSpecificSuffixSearchList
928+
$conf = ""
929+
ForEach ($ip in $server_ips) {
930+
$conf = $conf + "nameserver $ip`r`n"
931+
}
932+
$conf = $conf + "search $search_list"
933+
$hostdns_conf = "${env:CNI_CONFIG_DIR}\hostdns.conf"
934+
New-Item -Force -ItemType file ${hostdns_conf} | Out-Null
935+
Set-Content ${hostdns_conf} $conf
936+
Log-Output "HOST dns conf:`n$(Get-Content -Raw ${hostdns_conf})"
937+
}
938+
916939
# Fetches the kubelet config from the instance metadata and puts it at
917940
# $env:KUBELET_CONFIG.
918941
function Configure-Kubelet {

0 commit comments

Comments
 (0)