From 37289e2600c2c312113b20b6afcd69221703bc50 Mon Sep 17 00:00:00 2001 From: "Jingzhao.Ni" Date: Fri, 16 Aug 2019 18:23:49 +0800 Subject: [PATCH] Add some options for IEC installation scripts 1. Some options were added into the startup.sh script. "-k|--kube" ---- The version of k8s "-c|--cni-ver" ---- Kubernetes-cni version "-C|--cni" ---- CNI type: calico/flannel 2. In config file, those default values were also set. 3. Some log inforamtion about those parameters was add for varification when deploying the IEC infrastructure by startup.sh. Change-Id: Ief59d31b7630dc3247305f869ea55137142b040c Signed-off-by: Jingzhao.Ni --- src/foundation/scripts/config | 10 +++- src/foundation/scripts/k8s_common.sh | 15 +++--- src/foundation/scripts/k8s_worker.sh | 4 +- src/foundation/scripts/setup-cni.sh | 8 ++++ src/foundation/scripts/startup.sh | 89 ++++++++++++++++++++++++++++-------- 5 files changed, 97 insertions(+), 29 deletions(-) diff --git a/src/foundation/scripts/config b/src/foundation/scripts/config index 1a541a7..a1ad323 100755 --- a/src/foundation/scripts/config +++ b/src/foundation/scripts/config @@ -26,4 +26,12 @@ K8S_WORKER_GROUP=( "10.169.40.106,123456" ) - +# K8s parameter +CLUSTER_IP=172.16.1.136 # Align with the value in our K8s setup script +POD_NETWORK_CIDR=192.168.0.0/16 +#CNI type: flannel/calico/contivvpp +CNI_TYPE=calico +#kubernetes-cni version 0.7.5/ 0.6.0 +CNI_VERSION=0.6.0 +#kubernetes version: 1.15.2/ 1.13.0 +KUBE_VERSION=1.13.0 diff --git a/src/foundation/scripts/k8s_common.sh b/src/foundation/scripts/k8s_common.sh index d9c536f..735c307 100755 --- a/src/foundation/scripts/k8s_common.sh +++ b/src/foundation/scripts/k8s_common.sh @@ -9,14 +9,14 @@ fi case ${OS_ID_LIKE:-} in debian) DOCKER_VERSION=18.06.1~ce~3-0~ubuntu - KUBE_VERSION=1.13.0-00 - K8S_CNI_VERSION=0.6.0-00 + KUBE_VERSION=${1:-1.13.0}-00 + K8S_CNI_VERSION=${2:-0.6.0}-00 KUBELET_CFG=/etc/default/kubelet ;; rhel) DOCKER_VERSION=18.06.1.ce-3.el7 - KUBE_VERSION=1.13.0-0 - K8S_CNI_VERSION=0.6.0-0 + KUBE_VERSION=${1:-1.13.0}-0 + K8S_CNI_VERSION=${2:-0.6.0}-0 KUBELET_CFG=/etc/sysconfig/kubelet ;; *) @@ -25,6 +25,7 @@ rhel) ;; esac + case ${OS_ID_LIKE:-} in debian) # Install basic software @@ -88,8 +89,10 @@ EOF esac # Add extra flags to Kubelet -if ! grep -q -e 'fail-swap-on' $KUBELET_CFG; then - sudo sed 's/KUBELET_EXTRA_ARGS=/KUBELET_EXTRA_ARGS=--fail-swap-on=false --feature-gates HugePages=false/' -i $KUBELET_CFG +if [ ! -f "$KUBELET_CFG" ]; then + echo 'KUBELET_EXTRA_ARGS=--fail-swap-on=false' | sudo tee $KUBELET_CFG > /dev/null +elif ! grep -q -e 'fail-swap-on' $KUBELET_CFG; then + sudo sed 's/KUBELET_EXTRA_ARGS=/KUBELET_EXTRA_ARGS=--fail-swap-on=false/' -i $KUBELET_CFG fi sudo systemctl enable docker kubelet diff --git a/src/foundation/scripts/k8s_worker.sh b/src/foundation/scripts/k8s_worker.sh index 4d31db1..ba2b261 100755 --- a/src/foundation/scripts/k8s_worker.sh +++ b/src/foundation/scripts/k8s_worker.sh @@ -2,7 +2,5 @@ set -o xtrace set -e -#install essential software -source k8s_common.sh - # install kubernetes + diff --git a/src/foundation/scripts/setup-cni.sh b/src/foundation/scripts/setup-cni.sh index 55953a2..b383b97 100755 --- a/src/foundation/scripts/setup-cni.sh +++ b/src/foundation/scripts/setup-cni.sh @@ -36,6 +36,10 @@ install_flannel(){ kubectl apply -f "${SCRIPTS_DIR}/cni/flannel/kube-flannel.yml" } +install_contiv(){ + # Install the Contiv-vpp + echo "World peach!!!!!!!!!!!!!!" +} case ${CNI_TYPE} in 'calico') @@ -46,6 +50,10 @@ case ${CNI_TYPE} in echo "Install flannel ..." install_flannel ;; + 'contivvpp') + echo "Install Contiv-vpp ..." + install_contiv + ;; *) echo "${CNI_TYPE} does not supportted" exit 1 diff --git a/src/foundation/scripts/startup.sh b/src/foundation/scripts/startup.sh index 01783bc..f9a41e9 100755 --- a/src/foundation/scripts/startup.sh +++ b/src/foundation/scripts/startup.sh @@ -18,15 +18,25 @@ display_help () { echo "used to install the corresponding software on master and" echo "worker nodes. At the same time, this user should be enable to" echo "run the sudo command without input password on the hosts." - echo " " + echo "" + echo "In the end, some optional parameters could be directly passed" + echo "to startup.sh by shell for easy customizing your own IEC" + echo "environments:" + echo "-k|--kube: ---- The version of k8s" + echo "-c|--cni-ver: ---- Kubernetes-cni version" + echo "-C|--cni: ---- CNI type: calico/flannel" + echo "" echo "Example usages:" - echo " ./startup.sh" + echo " ./startup.sh #Deploy with default parameters" + echo " #Deploy the flannel with 1.15.2 K8s" + echo " ./startup.sh -C flannel -k 1.15.2 -c 0.7.5" + exit } # -# Deploy k8s with calico. +# Deploy k8s. # deploy_k8s () { set -o xtrace @@ -34,15 +44,17 @@ deploy_k8s () { INSTALL_SOFTWARE="sudo apt-get update && sudo apt-get install -y git &&\ sudo rm -rf ~/.kube ~/iec &&\ git clone ${REPO_URL} &&\ - cd iec/src/foundation/scripts/ && source k8s_common.sh" + cd iec/src/foundation/scripts/ && source k8s_common.sh $KUBE_VERSION $CNI_VERSION" #Automatic deploy the K8s environments on Master node SETUP_MASTER="cd iec/src/foundation/scripts/ && source k8s_master.sh ${K8S_MASTER_IP}" sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${INSTALL_SOFTWARE} sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_MASTER} | tee ${LOG_FILE} - KUBEADM_JOIN_CMD=$(grep "kubeadm join " ./${LOG_FILE}) + TOKEN_ID=$(grep "\--token " ./${LOG_FILE} | cut -f5 -d' ') + TOKEN_CA_SH256=$(grep "\--discovery-token-ca-cert-hash " ./${LOG_FILE} |cut -f2 -d':') + KUBEADM_JOIN_CMD="kubeadm join ${K8S_MASTER_IP}:6443 --token ${TOKEN_ID} --discovery-token-ca-cert-hash sha256:${TOKEN_CA_SH256}" #Automatic deploy the K8s environments on each worker-node SETUP_WORKER="cd iec/src/foundation/scripts/ && source k8s_worker.sh" @@ -63,8 +75,7 @@ deploy_k8s () { #Deploy etcd & CNI from master node - #There may be more options in future. e.g: Calico, Contiv-vpp, Ovn-k8s ... - SETUP_CNI="cd iec/src/foundation/scripts && source setup-cni.sh" + SETUP_CNI="cd iec/src/foundation/scripts && source setup-cni.sh $CLUSTER_IP $POD_NETWORK_CIDR $CNI_TYPE" sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_CNI} SETUP_HELM="cd iec/src/foundation/scripts && source helm.sh" sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_HELM} @@ -81,26 +92,66 @@ check_k8s_status(){ sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${VERIFY_K8S} } - # -# Init +# print environments # -if [ -n "$1" ]; -then - if [ $1 == "--help" ] || [ $1 == "-h" ]; - then - display_help - exit 0 - fi -fi +printOption(){ + echo "K8S_MASTER_IP:${K8S_MASTER_IP}" + echo "HOST_USER:${HOST_USER}" + echo "REPO_URL:${REPO_URL}" + + echo "The number of K8s-Workers:${#K8S_WORKER_GROUP[@]}" + for worker in "${K8S_WORKER_GROUP[@]}" + do + ip_addr="$(cut -d',' -f1 <<<${worker})" + passwd="$(cut -d',' -f2 <<<${worker})" + echo "Install & Deploy on ${ip_addr}. password:${passwd}" + done + + echo "KUBE_VERSION: ${KUBE_VERSION}" + echo "CNI_TPYE: ${CNI_TYPE}" + echo "CLUSTER_IP: ${CLUSTER_IP}" + echo "POD_NETWORK_CIDR: ${POD_NETWORK_CIDR}" +} # Read the configuration file source config -echo "The number of K8s-Workers:${#K8S_WORKER_GROUP[@]}" - rm -f "${LOG_FILE}" +ARGS=`getopt -a -o C:k:c:h -l cni:,kube:,cni-ver:,help -- "$@"` +eval set -- "${ARGS}" +while true +do + case "$1" in + -C|--cni) + CNI_TYPE="$2" + echo "CNI_TYPE=$2" + shift + ;; + -k|--kube) + echo "This is config kube version:$2" + KUBE_VERSION="$2" + shift + ;; + -c|--cni-ver) + echo "This is config cni version:$2" + CNI_VERSION="$2" + shift + ;; + -h|--help) + echo "this is help case" + display_help + ;; + --) + printOption + shift + break + ;; + esac +shift +done + deploy_k8s sleep 20 -- 2.16.6