From 55fbf4451a30337c7db112433126c07c091dbc07 Mon Sep 17 00:00:00 2001 From: trevor tao Date: Mon, 11 Apr 2022 19:45:58 +0800 Subject: [PATCH] Use Hostname instead of IP to install k8s Signed-off-by: trevor tao Change-Id: Ieed2a2e9f9eb2956d5413a99f872370eb72900e4 --- src/foundation/scripts/k8s_master.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/foundation/scripts/k8s_master.sh b/src/foundation/scripts/k8s_master.sh index 5cce155..13b76cd 100755 --- a/src/foundation/scripts/k8s_master.sh +++ b/src/foundation/scripts/k8s_master.sh @@ -5,6 +5,10 @@ # Use the src of the default route as the default local IP DEF_SRC_IP=$(ip route get 8.8.8.8 | awk '{ for (nn=1;nn<=NF;nn++) if ($nn~"src") print $(nn+1) }') MGMT_IP=${1:-${DEF_SRC_IP}} +MGMT_HOST=$(nslookup $MGMT_IP | grep "in-addr.arpa" | cut -d " " -f 3 | awk '{ print substr( $0, 1, length($0)-1 ) }') || true +#MGMT_HOST=$(nslookup $MGMT_IP | grep "in-addr.arpa" | cut -d " " -f 3 | sed 's/.$//') || true +echo $MGMT_HOST + POD_NETWORK_CIDR=${2:-192.168.0.0/16} SERVICE_CIDR=${3:-172.16.1.0/24} @@ -13,11 +17,20 @@ if [ -z "${MGMT_IP}" ]; then exit 1 fi +if [ -z "${MGMT_HOST}" ]; then + echo "MGMT HOST is not set, using MGMT_IP instead." + MGMT_HOST=$MGMT_IP +fi + if ! kubectl get nodes --request-timeout=3s; then sudo kubeadm config images pull + #sudo kubeadm init \ + # --pod-network-cidr="${POD_NETWORK_CIDR}" \ + # --apiserver-advertise-address="${MGMT_IP}" \ + # --service-cidr="${SERVICE_CIDR}" sudo kubeadm init \ --pod-network-cidr="${POD_NETWORK_CIDR}" \ - --apiserver-advertise-address="${MGMT_IP}" \ + --apiserver-advertise-address="${MGMT_HOST}" \ --service-cidr="${SERVICE_CIDR}" if [ "$(id -u)" = 0 ]; then -- 2.16.6