Use Hostname instead of IP to install k8s 92/4792/1
authortrevor tao <trevor.tao@arm.com>
Mon, 11 Apr 2022 11:45:58 +0000 (19:45 +0800)
committertrevor tao <trevor.tao@arm.com>
Mon, 11 Apr 2022 11:45:58 +0000 (19:45 +0800)
Signed-off-by: trevor tao <trevor.tao@arm.com>
Change-Id: Ieed2a2e9f9eb2956d5413a99f872370eb72900e4

src/foundation/scripts/k8s_master.sh

index 5cce155..13b76cd 100755 (executable)
@@ -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