X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ffoundation%2Fscripts%2Fk8s_common.sh;h=2aae30f338c6eba9a0b9b3692d415bd9d3569a96;hb=55fbf4451a30337c7db112433126c07c091dbc07;hp=9a4483419c123830066a48747f28d4aca7768368;hpb=2fe3d7c689341cc5e25678416c4f035ef3e5c96a;p=iec.git diff --git a/src/foundation/scripts/k8s_common.sh b/src/foundation/scripts/k8s_common.sh index 9a44834..2aae30f 100755 --- a/src/foundation/scripts/k8s_common.sh +++ b/src/foundation/scripts/k8s_common.sh @@ -1,34 +1,107 @@ #!/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} +if grep -q -e rhel /etc/*-release; then + OS_ID_LIKE=rhel +elif grep -q -e debian /etc/*-release; then + OS_ID_LIKE=debian +fi + +case ${OS_ID_LIKE:-} in +debian) + DOCKER_VERSION=18.06.1~ce~3-0~ubuntu + KUBE_VERSION=${1:-1.19.0}-00 + K8S_CNI_VERSION=${2:-0.8.6}-00 + KUBELET_CFG=/etc/default/kubelet + ;; +rhel) + DOCKER_VERSION=18.06.1.ce-3.el7 + KUBE_VERSION=${1:-1.19.0}-0 + K8S_CNI_VERSION=${2:-0.8.6}-0 + KUBELET_CFG=/etc/sysconfig/kubelet + ;; +*) + echo 'Unsupported distribution detected!' + exit 1 + ;; +esac + + +case ${OS_ID_LIKE:-} in +debian) + # Install basic software + echo "Acquire::ForceIPv4 \"true\";" | sudo tee -a /etc/apt/apt.conf.d/99force-ipv4 > /dev/null + sudo apt update + sudo apt install -y software-properties-common apt-transport-https curl python-pip + + # Install Docker as Prerequisite + curl -4fsSL 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} + sudo apt install -y docker-ce + ;; +rhel) + sudo yum install -y yum-utils device-mapper-persistent-data lvm2 + sudo yum-config-manager --add-repo \ + https://download.docker.com/linux/centos/docker-ce.repo + sudo yum install -y \ + docker-ce-$DOCKER_VERSION \ + docker-ce-cli-$DOCKER_VERSION \ + containerd.io + ;; +esac # 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 - +case ${OS_ID_LIKE:-} in +debian) + # Install Kubernetes with Kubeadm + curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - -cat < /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 +sudo systemctl restart docker kubelet +sudo modprobe br_netfilter _conf='/etc/sysctl.d/99-akraino-iec.conf' echo 'net.bridge.bridge-nf-call-iptables = 1' |& sudo tee "${_conf}" +# Set memory overcommit to 0 for extra checks during memory allocation +echo 'vm.overcommit_memory = 0' |& sudo tee -a "${_conf}" sudo sysctl -q -p "${_conf}"