Making the script more rebust for reinstalling k8s stack.
Change-Id: I68e6a225952b74532bca4b364a95056b9bcc34e4
Signed-off-by: wrider <lji@research.att.com>
# because cloud init user data has a 16kB limit, remove all comment lines to save space.
# except for the #! line
# 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"
-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
# install low latency kernel, docker.io, and kubernetes
apt-get update
# install low latency kernel, docker.io, and kubernetes
apt-get update
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"
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"
apt-get install -y linux-image-4.15.0-45-lowlatency
fi
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 "
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
if [ -z ${DOCKERVERSION} ]; then
apt-get install -y $APTOPTS docker.io
else
kubectl get pods --all-namespaces
# install flannel
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)
# waiting for all 8 kube-system pods to be in running state
# (at this point, minions have not joined yet)
# install Helm
HELMV=$(cat /opt/config/helm_version.txt)
HELMVERSION=${HELMV}
# 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
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
mv linux-amd64/helm /usr/local/bin/helm
rm -rf /root/.helm
export HELM_HOME="/root/.helm"
# waiting for tiller pod to be in running state
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
while ! helm version; do
echo "Waiting for Helm to be ready"
sleep 15
docker pull ${__RUNRICENV_DOCKER_HOST__}:${__RUNRICENV_DOCKER_PORT__}/whoami:0.0.1
fi
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