-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-master.sh
105 lines (84 loc) · 3.13 KB
/
install-master.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
#!/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
function get_random_string () {
random_string=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w $1 | head -n 1)
echo $random_string
}
env
# 서버단에서 내려줘야 함.
ADVERTISE_NET_DEV=${ADVERTISE_NET_DEV:-enp0s8}
ADVERTISE_ADDR=$(ifconfig $ADVERTISE_NET_DEV | grep 'inet' | cut -d: -f2 | awk '{print $2}')
JOIN_TOKEN=${JOIN_TOKEN:-"$(get_random_string 6).$(get_random_string 16)"}
KUBERNETES_VERSION=${KUBERNETES_VERSION:-latest}
KUBERNETES_CNI_VERSION=${KUBERNETES_CNI_VERSION:-latest}
CONTAINERD_VERSION=${CONTAINERD_VERSION:-latest}
# master 파일 다운
echo [Donwload master.yaml]
curl -O https://raw.githubusercontent.com/AI-Ocean/kubernetes-install-scripts/main/master.yaml
echo Done.
sed -i $(eval echo 's/JOIN_TOKEN/$JOIN_TOKEN/g') master.yaml
sed -i $(eval echo 's/ADVERTISE_ADDR/$ADVERTISE_ADDR/g') master.yaml
echo [Install Prerequest packages]
apt-get update
apt-get install -y apt-transport-https curl
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.teml
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
mv temp.toml /etc/containerd/config.teml
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
# Run kubeadm
echo [Run kubeadm]
kubeadm init \
--config master.yaml
# Prepare kubeconfig file for download to local machine
mkdir -p /root/.kube
cp -i /etc/kubernetes/admin.conf /root/.kube/config
chown root:root /root/.kube/config