forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_kubernetes.sh
executable file
·72 lines (62 loc) · 2.54 KB
/
install_kubernetes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
cidir=$(dirname "$0")
source "${cidir}/lib.sh"
KATA_HYPERVISOR="${KATA_HYPERVISOR:-qemu}"
echo "Install Kubernetes components"
cidir=$(dirname "$0")
source /etc/os-release || source /usr/lib/os-release
kubernetes_version=$(get_version "externals.kubernetes.version")
ARCH=$("${cidir}"/kata-arch.sh -d)
if [ "$ID" == "ubuntu" ]; then
if [ "$(command -v kubelet)" != "" ]; then
sudo -E apt purge kubelet -y
fi
sudo bash -c "cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb http://packages.cloud.google.com/apt/ kubernetes-xenial-unstable main
EOF"
chronic sudo -E sed -i 's/^[ \t]*//' /etc/apt/sources.list.d/kubernetes.list
curl -fsSL https://dl.k8s.io/apt/doc/apt-key.gpg | sudo apt-key add -
chronic sudo -E apt update
chronic sudo -E apt install --allow-downgrades -y kubelet="$kubernetes_version" kubeadm="$kubernetes_version" kubectl="$kubernetes_version"
elif [[ "$ID" =~ ^(alinux|centos|fedora|rhel)$ ]]; then
if [ "$(command -v kubelet)" != "" ]; then
sudo -E yum autoremove kubelet -y
fi
url="https://packages.cloud.google.com/yum/repos/kubernetes-el7-${ARCH}"
echo "Install ${url} for ${ARCH}"
sudo bash -c "cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=${url}
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF"
chronic sudo -E sed -i 's/^[ \t]*//' /etc/yum.repos.d/kubernetes.repo
install_kubernetes_version=$(echo $kubernetes_version | cut -d'-' -f1)
chronic sudo -E yum install -y kubelet-"$install_kubernetes_version" kubeadm-"$install_kubernetes_version" kubectl-"$install_kubernetes_version" --disableexcludes=kubernetes
# Disable selinux
if [ "$(getenforce)" != "Disabled" ]; then
chronic sudo -E setenforce 0
chronic sudo -E sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
fi
# Packets traversing the bridge should be sent to iptables for processing
echo br_netfilter | sudo -E tee /etc/modules-load.d/k8s.conf
sudo -E modprobe -i br_netfilter
sudo -E bash -c 'echo "net.bridge.bridge-nf-call-ip6tables = 1" > /etc/sysctl.d/k8s.conf'
sudo -E bash -c 'echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.d/k8s.conf'
sudo -E bash -c 'echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.d/k8s.conf'
sudo -E sysctl --system
sudo -E systemctl enable kubelet
else
die "Kubernetes configuration not done on $ID"
fi