Merge "Kubernetes optimised for Centos and Ubuntu"
[eliot.git] / scripts / setup.sh
index e1b04a4..15e5a84 100755 (executable)
 # sshpass needs to be installed before executing this script.                          #
 ########################################################################################
 
+# constants
+
+OSPLATFORM=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
+
+
 show_help()
 {
   echo "The script helps in setting up the ELIOT Toplogy Infrastrucutre"
@@ -36,7 +41,7 @@ show_help()
 # Installing Docker, K8S and Initializing K8S Master
 setup_k8smaster()
 {
-  set -o xtrace
+  #set -o xtrace
   sudo rm -rf ~/.kube
   source common.sh | tee eliotcommon.log
   source k8smaster.sh | tee kubeadm.log
@@ -56,7 +61,7 @@ setup_k8sworkers()
   #SETUP_WORKER_COMMON="cd eliot/scripts && source common.sh"
   SETUP_WORKER="cd eliot/scripts/ && source k8sworker.sh"
 
-  KUBEADM_JOIN=$(grep "kubeadm join " ./kubeadm.log)
+  KUBEADM_JOIN=$(grep "kubeadm join" ./kubeadm.log)
   KUBEADM_JOIN="sudo ${KUBEADM_JOIN}"
 
  # Read all the Worker Node details from nodelist file.
@@ -73,6 +78,48 @@ setup_k8sworkers()
 
 }
 
+setup_k8smaster_centos()
+{
+  set -o xtrace
+  sudo rm -rf ~/.kube
+  source common_centos.sh | tee eliotcommon_centos.log
+  source k8smaster_centos.sh | tee kubeadm_centos.log
+
+  # Setup ELIOT Node
+  setup_k8sworkers_centos
+
+  cd cni/calico
+  kubectl apply -f rbac.yaml
+  kubectl apply -f calico.yaml
+}
+
+
+setup_k8sworkers_centos()
+{
+  set -o xtrace
+  # Install Docker on ELIOT Node
+
+  ELIOT_REPO="https://gerrit.akraino.org/r/eliot"
+  SETUP_WORKER_COMMON_CENTOS="sudo rm -rf ~/eliot &&\
+                              git clone ${ELIOT_REPO} &&\
+                              cd eliot/scripts && source common_centos.sh"
+
+  KUBEADM_TOKEN=$(sudo kubeadm token create --print-join-command)
+  KUBEADM_JOIN_CENTOS="sudo ${KUBEADM_TOKEN}"
+
+ # Read all the Worker Node details from nodelist file.
+ while read line
+ do
+     nodeinfo="${line}"
+     nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
+     nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
+     nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_COMMON_CENTOS} < /dev/null
+     #sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_CENTOS} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${KUBEADM_JOIN_CENTOS} < /dev/null
+ done < nodelist
+
+}
 
 #verify kubernetes setup by deploying nginx server.
 
@@ -108,13 +155,16 @@ then
   exit 0
 fi
 
+if [[ $OSPLATFORM = *CentOS* ]]; then
+   setup_k8smaster_centos
+else
+   setup_k8smaster
+fi
 
-setup_k8smaster
 sleep 20
 verify_k8s_status
-
 install_cadvisor_edge
 sleep 10
 install_prometheus
-sleep 5 
+sleep 5
 sudo docker ps | grep prometheus