From 3ca639186156bb294424f4979b30bf7804c77ae2 Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Wed, 13 Feb 2019 15:58:41 +0100 Subject: [PATCH] Sync bootstrap scripts from Akraino IEC wiki Bring in sh scripts from IEC Wiki page [1]: The initial setup scripts to be executed on all cluster nodes: - k8s_common: * prerequisites; * Kubernetes Install for Ubuntu, using Kubeadm; The following scripts should be executed on K8s master node: - k8s_master: * setup host as K8s master; - calico: * setup etcd, RBAC roles, calico; - nginx: * verify basic K8s functionality; - helm: * bring in `tiller` and `helm` binaries; There is one more step that is not covered by the current scripts: - K8s slave nodes should execute `kubeadm join` after the k8s_master script has completed; [1] https://wiki.akraino.org/display/AK/\ IEC+Blueprints+Installation+Overview Change-Id: I8d4f78b7482486e2c4a31db35cddb0c1570307a5 Signed-off-by: Alexandru Avadanii --- scripts/calico.sh | 29 +++++++++++++++++++++++ scripts/helm.sh | 18 +++++++++++++++ scripts/k8s_common.sh | 34 +++++++++++++++++++++++++++ scripts/k8s_master.sh | 30 ++++++++++++++++++++++++ scripts/nginx.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 175 insertions(+) create mode 100755 scripts/calico.sh create mode 100755 scripts/helm.sh create mode 100755 scripts/k8s_common.sh create mode 100755 scripts/k8s_master.sh create mode 100755 scripts/nginx.sh diff --git a/scripts/calico.sh b/scripts/calico.sh new file mode 100755 index 0000000..922d226 --- /dev/null +++ b/scripts/calico.sh @@ -0,0 +1,29 @@ +#!/bin/bash -ex + +CLUSTER_IP=${1:-172.16.1.136} # Align with the value in our K8s setup script +CALICO_URI_ROOT=https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation + +# Install the Etcd Database +if [ "$(uname -m)" == 'aarch64' ]; then + ETCD_YAML=https://raw.githubusercontent.com/Jingzhao123/arm64TemporaryCalico/temporay_arm64/v3.3/getting-started/kubernetes/installation/hosted/etcd-arm64.yaml +else + ETCD_YAML=${CALICO_URI_ROOT}/hosted/etcd.yaml +fi +wget -O etcd.yaml "${ETCD_YAML}" +sed -i "s/10.96.232.136/${CLUSTER_IP}/" etcd.yaml +kubectl apply -f etcd.yaml + +# Install the RBAC Roles required for Calico +kubectl apply -f "${CALICO_URI_ROOT}/rbac.yaml" + +# Install Calico to system +wget -O calico.yaml "${CALICO_URI_ROOT}/hosted/calico.yaml" +sed -i "s/10.96.232.136/${CLUSTER_IP}/" calico.yaml +if [ "$(uname -m)" == 'aarch64' ]; then + sed -i "s/quay.io\/calico/calico/" calico.yaml +fi +# FIXME: IP_AUTODETECTION_METHOD? +kubectl apply -f calico.yaml + +# Remove the taints on master node +kubectl taint nodes --all node-role.kubernetes.io/master- || true diff --git a/scripts/helm.sh b/scripts/helm.sh new file mode 100755 index 0000000..524a770 --- /dev/null +++ b/scripts/helm.sh @@ -0,0 +1,18 @@ +#!/bin/bash -ex + +VERSION='v2.12.3' +if [ "$(uname -m)" == 'aarch64' ]; then + FLAVOR='linux-arm64' +else + FLAVOR='linux-amd64' +fi + +URI_ROOT='https://storage.googleapis.com/kubernetes-helm' +TGZ_NAME="helm-${VERSION}-${FLAVOR}.tar.gz" + +if [ ! -e /usr/bin/helm ] || [ ! -e /usr/bin/tiller ]; then + wget -O "/tmp/${TGZ_NAME}" "${URI_ROOT}/${TGZ_NAME}" + sudo tar xpPf "/tmp/${TGZ_NAME}" --overwrite \ + --transform "s|${FLAVOR}|/usr/bin|" "${FLAVOR}/"{helm,tiller} + rm -f "/tmp/${TGZ_NAME}" +fi diff --git a/scripts/k8s_common.sh b/scripts/k8s_common.sh new file mode 100755 index 0000000..bf3216f --- /dev/null +++ b/scripts/k8s_common.sh @@ -0,0 +1,34 @@ +#!/bin/bash -ex + +DOCKER_VERSION=18.06.1~ce~3-0~ubuntu +KUBE_VERSION=1.13.0-00 + +# Install Docker as Prerequisite +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - +sudo apt-key fingerprint 0EBFCD88 +sudo add-apt-repository \ + "deb https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) \ + stable" +sudo apt update +sudo apt install -y docker-ce=${DOCKER_VERSION} + +# Disable swap on your machine +sudo swapoff -a + +# Install Kubernetes with Kubeadm +sudo apt update +sudo apt install -y apt-transport-https curl +curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - + +cat < "${NGINX_APP}" +apiVersion: v1 +kind: Service +metadata: + name: nginx + labels: + app: nginx +spec: + type: NodePort + ports: + - port: 80 + protocol: TCP + name: http + selector: + app: nginx +--- +apiVersion: v1 +kind: ReplicationController +metadata: + name: nginx +spec: + replicas: 2 + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 +EOF + +if ! kubectl get services | grep -q nginx; then + kubectl create -f "${NGINX_APP}" +fi +kubectl get nodes +kubectl get services +kubectl get pods +kubectl get rc + +attempts=60 +while [ $attempts -gt 0 ] +do + if [ 3 == "$(kubectl get pods | grep -c -e STATUS -e Running)" ]; then + break + fi + ((attempts-=1)) + sleep 10 +done +[ $attempts -gt 0 ] || exit 1 + +svcip=$(kubectl get services nginx -o json | grep clusterIP | cut -f4 -d'"') +sleep 10 +wget "http://$svcip" +kubectl delete -f "${NGINX_APP}" +kubectl get rc +kubectl get pods +kubectl get services -- 2.16.6