-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathinstall_k8s_packages.sh
executable file
·115 lines (94 loc) · 3.27 KB
/
install_k8s_packages.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
### enable debug
#set -exvfC
set -e
### User Setting
# TODO(@fujitatomoya) add KubeEdge installation
KUBERNETES_VERSION=v1.26
### Confirmation to install all dependent packages
echo "-------------------------------------------------------------------"
echo "This will reinstall the all depedent packages, including removing installed pacakges."
echo "golang, containerd, docker and kubernetes related packages will be reinstalled with specific version."
echo "*** Basically this needs to be done only once for each system ***"
echo "-------------------------------------------------------------------"
while true; do
read -p "Do you want to proceed? (yes/no) " yn
case $yn in
yes ) echo OK, we will proceed;
break;;
no ) echo exiting...;
exit;;
* ) echo invalid response;
esac
done
### Functions Implementation
function exit_trap() {
if [ $? != 0 ]; then
echo "Command [$BASH_COMMAND] is failed"
exit 1
fi
}
function check_sudo() {
if [ "$EUID" -ne 0 ]; then
echo "Please run this script with sudo."
exit 1
fi
}
function install_container_runtime () {
trap exit_trap ERR
apt remove -y containerd docker.io
apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common dpkg-dev gnupg2
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository -y "deb [arch=$(dpkg-architecture -q DEB_BUILD_ARCH)] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update -y
apt install -y docker-ce docker-ce-cli containerd.io
mkdir -p /etc/containerd
containerd config default | tee /etc/containerd/config.toml
sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
systemctl restart containerd
systemctl enable containerd
systemctl restart docker
systemctl enable docker
docker version
}
function install_kubernetes () {
trap exit_trap ERR
apt remove -y --allow-change-held-packages kubelet kubectl kubeadm
apt install -y apt-transport-https ca-certificates curl
curl -fsSL https://pkgs.k8s.io/core:/stable:/$KUBERNETES_VERSION/deb/Release.key | gpg --yes --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/$KUBERNETES_VERSION/deb/ /" | tee /etc/apt/sources.list.d/kubernetes.list
apt update -y
apt install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
kubeadm version
### kubectl version will try to access server that leads to error to exit this script
kubectl version --client
}
function install_golang () {
trap exit_trap ERR
add-apt-repository -y ppa:longsleep/golang-backports
apt update
### golang-1.21 or later should be fine, just installing
apt install -y golang-1.21 golang-go
go version
}
function install_kind () {
trap exit_trap ERR
go install sigs.k8s.io/[email protected]
### kind needs to be in path
$HOME/go/bin/kind version
}
### Main
# set the trap on error
trap exit_trap ERR
check_sudo
echo "Install Container Runtime ----------"
install_container_runtime
echo "Install Kubernetes ----------"
install_kubernetes
echo "Install Golang ----------"
install_golang
echo "Install KIND ----------"
install_kind
echo "Installation completed, enjoy your cluster !!!"
exit 0