From f3742e2f6b6826f2e3154529901e8ee9a10269d5 Mon Sep 17 00:00:00 2001 From: VALKIRIA ACUATICA <56233573+valkiriaaquatica@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:47:35 +0200 Subject: [PATCH 1/2] interface as variable --- scripts/common.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/common.sh b/scripts/common.sh index d5c9685..9167e96 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -77,7 +77,10 @@ sudo apt-mark hold kubelet kubeadm kubectl sudo apt-get install -y jq -local_ip="$(ip --json addr show eth0 | jq -r '.[0].addr_info[] | select(.family == "inet") | .local')" +# detects the network interface +interface=$(ip route | grep default | awk '{print $5}') + +local_ip="$(ip --json addr show $interface | jq -r '.[0].addr_info[] | select(.family == "inet") | .local')" cat > /etc/default/kubelet << EOF KUBELET_EXTRA_ARGS=--node-ip=$local_ip EOF From a06452ef5c13f1a338f05f25ae7731a81396bc8d Mon Sep 17 00:00:00 2001 From: VALKIRIA ACUATICA <56233573+valkiriaaquatica@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:49:30 +0200 Subject: [PATCH 2/2] change to variable also in master --- scripts/master.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/master.sh b/scripts/master.sh index 026e512..eebe548 100755 --- a/scripts/master.sh +++ b/scripts/master.sh @@ -14,11 +14,14 @@ POD_CIDR="192.168.0.0/16" sudo kubeadm config images pull +# detects the network interface +interface=$(ip route | grep default | awk '{print $5}') + # Initialize kubeadm based on PUBLIC_IP_ACCESS if [[ "$PUBLIC_IP_ACCESS" == "false" ]]; then - MASTER_PRIVATE_IP=$(ip addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1) + MASTER_PRIVATE_IP=$(ip addr show "$interface" | awk '/inet / {print $2}' | cut -d/ -f1) sudo kubeadm init --apiserver-advertise-address="$MASTER_PRIVATE_IP" --apiserver-cert-extra-sans="$MASTER_PRIVATE_IP" --pod-network-cidr="$POD_CIDR" --node-name "$NODENAME" --ignore-preflight-errors Swap elif [[ "$PUBLIC_IP_ACCESS" == "true" ]]; then