-
Notifications
You must be signed in to change notification settings - Fork 32
/
install.sh
executable file
·100 lines (87 loc) · 3.16 KB
/
install.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
#!/bin/bash
# KUBE_REPO_PREFIX=registry.cn-hangzhou.aliyuncs.com/google-containers
# KUBE_HYPERKUBE_IMAGE=registry.cn-hangzhou.aliyuncs.com/google-containers/hyperkube-amd64:v1.7.0
# KUBE_DISCOVERY_IMAGE=registry.cn-hangzhou.aliyuncs.com/google-containers/kube-discovery-amd64:1.0
# KUBE_ETCD_IMAGE=registry.cn-hangzhou.aliyuncs.com/google-containers/etcd-amd64:3.0.17
# KUBE_REPO_PREFIX=$KUBE_REPO_PREFIX KUBE_HYPERKUBE_IMAGE=$KUBE_HYPERKUBE_IMAGE KUBE_DISCOVERY_IMAGE=$KUBE_DISCOVERY_IMAGE kubeadm init --ignore-preflight-errors=all --pod-network-cidr="10.244.0.0/16"
set -x
USER=ubuntu # 用户
GROUP=ubuntu # 组
FLANELADDR=https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
KUBECONF=/home/ubuntu/kubeadm.conf # 文件地址, 改成你需要的路径
REGMIRROR=YOUR_OWN_DOCKER_REGISTRY_MIRROR_URL # docker registry mirror 地址
# you can get the following values from `kubeadm init` output
# these are needed when creating node
MASTERTOKEN=YOUR_TOKEN
MASTERIP=MASTER_IP
MASTERPORT=MASTER_PORT
MASTERHASH=MASTER_HASH
install_docker() {
mkdir /etc/docker
mkdir -p /data/docker
cat << EOF > /tmp/daemon.json
{
"registry-mirrors": ["$REGMIRROR"],
"graph": "/data/docker"
}
EOF
apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
apt-get update && apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 17.09 | head -1 | awk '{print $3}')
}
add_user_to_docker_group() {
groupadd docker
gpasswd -a $USER docker # ubuntu is the user name
}
install_kube_commands() {
cat kube_apt_key.gpg | apt-key add -
echo "deb [arch=amd64] https://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-$(lsb_release -cs) main" >> /etc/apt/sources.list
apt-get update && apt-get install -y kubelet kubeadm kubectl
}
restart_kubelet() {
sed -i "s,ExecStart=$,Environment=\"KUBELET_EXTRA_ARGS=--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.1\"\nExecStart=,g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl daemon-reload
systemctl restart kubelet
}
enable_kubectl() {
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
}
# for now, better to download from original registry
apply_flannel() {
kubectl apply -f $FLANELADDR
}
case "$1" in
"pre")
install_docker
add_user_to_docker_group
install_kube_commands
;;
"kubernetes-master")
sysctl net.bridge.bridge-nf-call-iptables=1
restart_kubelet
kubeadm init --config $KUBECONF
;;
"kubernetes-node")
sysctl net.bridge.bridge-nf-call-iptables=1
restart_kubelet
kubeadm join --token $MASTERTOKEN $MASTERIP:$MASTERPORT --discovery-token-ca-cert-hash sha256:$MASTERHASH
;;
"post")
if [[ $EUID -ne 0 ]]; then
echo "do not run as root"
exit
fi
enable_kubectl
apply_flannel
;;
*)
echo "huh ????"
;;
esac