Add timeout to kubectl get node
[iec.git] / src / foundation / scripts / k8s_master.sh
index cdcf8bc..5cce155 100755 (executable)
@@ -2,7 +2,9 @@
 # shellcheck source=/dev/null
 
 # For host setup as Kubernetes master
-MGMT_IP=$1
+# 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}}
 POD_NETWORK_CIDR=${2:-192.168.0.0/16}
 SERVICE_CIDR=${3:-172.16.1.0/24}
 
@@ -11,7 +13,7 @@ if [ -z "${MGMT_IP}" ]; then
   exit 1
 fi
 
-if ! kubectl get nodes; then
+if ! kubectl get nodes --request-timeout=3s; then
   sudo kubeadm config images pull
   sudo kubeadm init \
     --pod-network-cidr="${POD_NETWORK_CIDR}" \