-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-worker.sh
123 lines (100 loc) · 3.37 KB
/
install-worker.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
116
117
118
119
120
121
122
123
#!/bin/bash -xe
# RUN AS ROOT
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
set -x
swapoff -a
# 서버단에서 내려줘야 함.
if [[ -z "$API_SERVER_ADDR" ]]
then
echo "API_SERVER_ADDR is not set. abort"
exit 1
fi
# 서버단에서 내려줘야 함.
if [[ -z "$JOIN_TOKEN" ]]
then
echo "JOIN_TOKEN is not set. abort"
exit 1
fi
# 서버단에서 내려줘야 함.
KUBERNETES_VERSION=${KUBERNETES_VERSION:-latest}
KUBERNETES_CNI_VERSION=${KUBERNETES_CNI_VERSION:-latest}
CONTAINERD_VERSION=${CONTAINERD_VERSION:-latest}
NODE_HOSTNAME=$(hostname)
echo
echo ==============================
echo KUBE VERSION: $KUBERNETES_VERSION
echo KUBE CNI VERSION: $KUBERNETES_CNI_VERSION
echo CONTAINERD VERSION: $CONTAINERD_VERSION
echo ==============================
echo
# worker 파일 다운
echo "[Donwload worker.yaml]"
curl -O https://raw.githubusercontent.com/AI-Ocean/kubernetes-install-scripts/main/worker.yaml
echo "Done."
sed -i 's/JOIN_TOKEN/'"$JOIN_TOKEN"'/g' worker.yaml
sed -i 's/API_SERVER_ADDR/'"$API_SERVER_ADDR"'/g' worker.yaml
sed -i 's/NODE_HOSTNAME/'"$NODE_HOSTNAME"'/g' worker.yaml
echo "[Install Prerequest packages]"
apt-get update
apt-get install -y apt-transport-https curl nfs-common
echo "[Containerd Install]"
if [ "$CONTAINERD_VERSION" = "latest" ]
then
apt-get install -y containerd
else
apt-get install -y containerd=$CONTAINERD_VERSION
fi
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
net.ipv4.conf.all.rp_filter = 1
EOF
sudo sysctl --system
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
# add private repo
sed '/\[plugins."io.containerd.grpc.v1.cri".registry.configs\]/a \\t[plugins."io.containerd.grpc.v1.cri".registry.configs."harbor.harbor.svc:80"]\n\t [plugins."io.containerd.grpc.v1.cri".registry.configs."harbor.harbor.svc:80".tls]\n\t insecure_skip_verify = true' /etc/containerd/config.toml > temp.toml
mv temp.toml /etc/containerd/config.toml
sed '/\[plugins."io.containerd.grpc.v1.cri".registry.mirrors\]/a \\t[plugins."io.containerd.grpc.v1.cri".registry.mirrors."harbor.harbor.svc:80"]\n\t endpoint = ["http://harbor.harbor.svc:80"]' /etc/containerd/config.toml > temp.toml
mv temp.toml /etc/containerd/config.toml
sudo systemctl restart containerd
echo "[Kubernetes install]"
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" >/etc/apt/sources.list.d/kubernetes.list
apt-get update
if [ "$KUBERNETES_VERSION" = "latest" ]
then
apt-get install -y kubelet kubeadm kubectl
else
apt-get install -y kubelet=$KUBERNETES_VERSION \
kubeadm=$KUBERNETES_VERSION \
kubectl=$KUBERNETES_VERSION
fi
echo "[Kubernetes CNI install]"
if [ "$KUBERNETES_CNI_VERSION" = "latest" ]
then
apt-get install -y kubernetes-cni
else
apt-get install -y kubernetes-cni=$KUBERNETES_CNI_VERSION
fi
echo "[Kubernetes API Server Health Check]"
until $(curl --output /dev/null --silent --fail https://$API_SERVER_ADDR:6443/healthz -k)
do
printf '.'
sleep 5
done
echo "API Server is running!"
echo "[Joining]"
# Run kubeadm
kubeadm join --config worker.yaml
echo "Done."