From ee3f897ca7bf7c35763324e1f674ea9c00bcf48c Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sun, 2 Feb 2020 17:58:01 -0500 Subject: [PATCH] update network-y stuff for supporting ubuntu/bionic as master On bionic, we don't have eth0 hard coded. example below, so we use `ip route` to figure out the default ethernet interface ``` dims@kubernetes-master:~$ ip link 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens4: mtu 1460 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether 42:01:0a:80:00:23 brd ff:ff:ff:ff:ff:ff 3: docker0: mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default link/ether 02:42:b2:4e:dd:86 brd ff:ff:ff:ff:ff:ff ``` Also, bionic uses systemd-resolver by default and adds entries in /etc/resolv.conf that CoreDNS does not link. So follow the recommendation in the documentation to specify resolv.conf explicitly --- cluster/gce/util.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 1bde4f43bc24..b0f12bd50f7b 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -765,6 +765,11 @@ function construct-linux-kubelet-flags { flags+=" --kubeconfig=/var/lib/kubelet/bootstrap-kubeconfig" flags+=" --register-schedulable=false" fi + if [[ "${MASTER_OS_DISTRIBUTION}" == "ubuntu" ]]; then + # Configure the file path for host dns configuration + # as ubuntu uses systemd-resolved + flags+=" --resolv-conf=/run/systemd/resolve/resolv.conf" + fi else # For nodes flags+=" ${NODE_KUBELET_TEST_ARGS:-}" flags+=" --bootstrap-kubeconfig=/var/lib/kubelet/bootstrap-kubeconfig" @@ -772,6 +777,11 @@ function construct-linux-kubelet-flags { if [[ "${node_type}" == "heapster" ]]; then flags+=" ${HEAPSTER_KUBELET_TEST_ARGS:-}" fi + if [[ "${NODE_OS_DISTRIBUTION}" == "ubuntu" ]]; then + # Configure the file path for host dns configuration + # as ubuntu uses systemd-resolved + flags+=" --resolv-conf=/run/systemd/resolve/resolv.conf" + fi fi # Network plugin if [[ -n "${NETWORK_PROVIDER:-}" || -n "${NETWORK_POLICY_PROVIDER:-}" ]]; then @@ -2925,7 +2935,7 @@ function attach-internal-master-ip() { echo "Setting ${name}'s aliases to '${aliases}' (added ${ip})" # Attach ${ip} to ${name} gcloud compute instances network-interfaces update "${name}" --project "${PROJECT}" --zone "${zone}" --aliases="${aliases}" - run-gcloud-command "${name}" "${zone}" "sudo ip route add to local ${ip}/32 dev eth0" + run-gcloud-command "${name}" "${zone}" 'sudo ip route add to local '${ip}'/32 dev $(ip route | grep default | awk '\''{print $5}'\'')' || true return $? } @@ -2943,7 +2953,7 @@ function detach-internal-master-ip() { echo "Setting ${name}'s aliases to '${aliases}' (removed ${ip})" # Detach ${MASTER_NAME}-internal-ip from ${name} gcloud compute instances network-interfaces update "${name}" --project "${PROJECT}" --zone "${zone}" --aliases="${aliases}" - run-gcloud-command "${name}" "${zone}" "sudo ip route del to local ${ip}/32 dev eth0" + run-gcloud-command "${name}" "${zone}" 'sudo ip route del to local '${ip}'/32 dev $(ip route | grep default | awk '\''{print $5}'\'')' || true return $? }