From: wrider Date: Thu, 20 Feb 2020 17:19:16 +0000 (-0500) Subject: Improving k8s cluster install scriipt X-Git-Tag: f-release~130^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=2ec06359823b93235ef110960b3e5cc05e3a1a80;p=it%2Fdep.git Improving k8s cluster install scriipt Making the script more rebust for reinstalling k8s stack. Change-Id: I68e6a225952b74532bca4b364a95056b9bcc34e4 Signed-off-by: wrider --- diff --git a/tools/k8s/bin/gen-cloud-init.sh b/tools/k8s/bin/gen-cloud-init.sh index d02ec1da..c0fe1600 100755 --- a/tools/k8s/bin/gen-cloud-init.sh +++ b/tools/k8s/bin/gen-cloud-init.sh @@ -144,8 +144,11 @@ sed -i -e "s/__stack_name__/\$(hostname)/g" "$filename" # because cloud init user data has a 16kB limit, remove all comment lines to save space. # except for the #! line -sed -i -e '/^[ \t]*#[^!]/d' "$filename" +sed -i -e '/^[ \t]*#[^!]/d' "$filename" chmod +x "$filename" -mv "$filename" ./k8s-1node-cloud-init.sh +K8SV=$(echo ${INFRA_K8S_VERSION} | cut -f 1-2 -d '.' | sed -e 's/\./_/g') +HV=$(echo ${INFRA_HELM_VERSION} | cut -f 1-2 -d '.' | sed -e 's/\./_/g') +DV=$(echo ${INFRA_DOCKER_VERSION} | cut -f 1-2 -d '.' | sed -e 's/\./_/g') +mv "$filename" ./k8s-1node-cloud-init-k_${K8SV:-cur}-h_${HV:-cur}-d_${DV:-cur}.sh diff --git a/tools/k8s/heat/scripts/k8s_vm_install.sh b/tools/k8s/heat/scripts/k8s_vm_install.sh index 2653f388..77641fa3 100644 --- a/tools/k8s/heat/scripts/k8s_vm_install.sh +++ b/tools/k8s/heat/scripts/k8s_vm_install.sh @@ -148,7 +148,7 @@ echo "APT::Acquire::Retries \"3\";" > /etc/apt/apt.conf.d/80-retries # install low latency kernel, docker.io, and kubernetes apt-get update -apt-get -y autoremove + RES=$(apt-get install -y virt-what curl jq netcat 2>&1) if [[ $RES == */var/lib/dpkg/lock* ]]; then echo "Fail to get dpkg lock. Wait for any other package installation" @@ -162,14 +162,25 @@ if ! echo $(virt-what) | grep "virtualbox"; then apt-get install -y linux-image-4.15.0-45-lowlatency fi -if kubeadm version; then - # remove existing Kubernetes installation - echo "Removing existing Kubernetes installation, version $(kubeadm version)" - kubeadm reset -f - rm -rf ~/.kube -fi - APTOPTS="--allow-downgrades --allow-change-held-packages --allow-unauthenticated --ignore-hold " + +# remove infrastructure stack if present +# note the order of the packages being removed. +for PKG in kubeadm docker.io; do + INSTALLED_VERSION=$(dpkg --list |grep ${PKG} |tr -s " " |cut -f3 -d ' ') + if [ ! -z ${INSTALLED_VERSION} ]; then + if [ "${PKG}" == "kubeadm" ]; then + kubeadm reset -f + rm -rf ~/.kube + apt-get -y $APTOPTS remove kubeadm kubelet kubectl kubernetes-cni + else + apt-get -y $APTOPTS remove "${PKG}" + fi + fi +done +apt-get -y autoremove + +# install docker if [ -z ${DOCKERVERSION} ]; then apt-get install -y $APTOPTS docker.io else @@ -308,11 +319,7 @@ EOF kubectl get pods --all-namespaces # install flannel - if [[ ${KUBEV} == 1.16.* ]]; then - kubectl apply -f "https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml" - else - kubectl apply -f "https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml" - fi + kubectl apply -f "https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml" # waiting for all 8 kube-system pods to be in running state # (at this point, minions have not joined yet) @@ -328,9 +335,11 @@ EOF # install Helm HELMV=$(cat /opt/config/helm_version.txt) HELMVERSION=${HELMV} + if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then + wget https://storage.googleapis.com/kubernetes-helm/helm-v${HELMVERSION}-linux-amd64.tar.gz + fi cd /root && rm -rf Helm && mkdir Helm && cd Helm - wget https://storage.googleapis.com/kubernetes-helm/helm-v${HELMVERSION}-linux-amd64.tar.gz - tar -xvf helm-v${HELMVERSION}-linux-amd64.tar.gz + tar -xvf ../helm-v${HELMVERSION}-linux-amd64.tar.gz mv linux-amd64/helm /usr/local/bin/helm rm -rf /root/.helm @@ -347,7 +356,6 @@ EOF export HELM_HOME="/root/.helm" # waiting for tiller pod to be in running state - wait_for_pods_running 1 kube-system tiller-deploy while ! helm version; do echo "Waiting for Helm to be ready" sleep 15 @@ -395,4 +403,4 @@ EOF docker pull ${__RUNRICENV_DOCKER_HOST__}:${__RUNRICENV_DOCKER_PORT__}/whoami:0.0.1 fi -if [ "$(uname -r)" != "4.15.0-45-lowlatency" ]; then reboot; fi +if [ "$(uname -r)" != "4.15.0-45-lowlatency" ]; then reboot; fi \ No newline at end of file