-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkpe.sh
423 lines (376 loc) · 10.1 KB
/
kpe.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#!/bin/bash
# This file allows you to init kuberenete master node with pouch containers available.
# Ubuntu and CentOS supported.
set -o errexit
set -o nounset
echo "----------------------------------"
echo "Whether to configure CNI config ?"
echo "(Y/y) Y"
echo "(N/n) N"
echo "(0) exit"
echo "----------------------------------"
read input
case $input in
Y | y )
CONFIG_CNI="true";;
N | n)
CONFIG_CNI="false";;
0)
exit;;
esac
echo "CONFIG_CNI:"$CONFIG_CNI
echo "----------------------------------"
echo "Is it the master node ?"
echo "(Y/y) Y"
echo "(N/n) N"
echo "(0) exit"
echo "----------------------------------"
read input
case $input in
Y | y )
MASTER_NODE="true";;
N | n)
MASTER_NODE="false";;
0)
exit;;
esac
echo "MASTER_NODE:"$MASTER_NODE
update_pouch="false"
cri_test="false"
e2e_test="false"
k8s_cluster="true"
e2e_focus="should report resource usage through the stats api"
KUBERNETES_VERSION="release-1.13"
KUBERNETES_VERSION_UBUNTU="1.13.1-00"
KUBERNETES_VERSION_CENTOS="1.11.5-0.x86_64"
MASTER_CIDR="10.244.0.0/16"
pouchd_log="pouchd.log"
pouch_github="https://github.com/Starnop/pouch.git"
pouch_github_branch="cri-1.12"
cri_version="v1alpha2"
kubeadm_log="kubeadm.log"
cri_tools_rlease="1.10"
cri_shim="/var/run/pouchcri.sock"
cri_validation_log="crivalidation.log"
APT_GPG="https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg"
# APT_GPG="https://packages.cloud.google.com/apt/doc/apt-key.gpg"
APT_SOURCE="https://mirrors.aliyun.com/kubernetes/apt/"
# APT_SOURCE="http://apt.kubernetes.io/"
# preparation
install_tools_ubuntu() {
apt-get update
apt-get install -y wget
apt-get install -y make
apt-get install -y gcc
apt-get install -y git
apt-get install -y socat
}
install_tools(){
yum -y install wget
yum -y install make
yum -y install gcc
yum -y install git
}
# public
install_go(){
wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.10.2.linux-amd64.tar.gz
}
setup_path(){
export GOROOT=/usr/local/go
export GOPATH=$HOME/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export PATH=$PATH:/usr/local/bin
}
install_ginkgo(){
go get -u github.com/onsi/ginkgo/ginkgo
}
# update_pouch
stop_pouch(){
COUNT=$(ps -ef |grep pouch |grep -v "grep" |wc -l)
echo $COUNT
if [ $COUNT -eq 0 ]; then
echo NOT RUN
else
ps -ef | grep pouch | grep -v grep | awk '{print $2}' | xargs kill -9
fi
}
# cri-tools validation
install_cri_tools(){
wget https://github.com/kubernetes-incubator/cri-tools/releases/download/v1.0.0-beta.0/critest-v1.0.0-beta.0-linux-amd64.tar.gz
sudo tar zxvf critest-v1.0.0-beta.0-linux-amd64.tar.gz -C /usr/local/bin
rm -f critest-v1.0.0-beta.0-linux-amd64.tar.gz
}
download_cri_tools(){
rm -rf /root/gopath/src/github.com/kubernetes-incubator/cri-tools
git clone https://github.com/kubernetes-incubator/cri-tools -b release-$cri_tools_rlease $GOPATH/src/github.com/kubernetes-incubator/cri-tools
}
run_cri_validation(){
cd
critest --runtime-endpoint $cri_shim --image-endpoint $cri_shim > $cri_validation_log 2>&1 &
}
# e2e test
install_etcd(){
wget https://github.com/coreos/etcd/releases/download/v3.3.5/etcd-v3.3.5-linux-amd64.tar.gz
tar -xzvf etcd-v3.3.5-linux-amd64.tar.gz -C /usr/local
export PATH=$PATH:/usr/local/etcd-v3.3.5-linux-amd64
}
get_kubernetes(){
rm -rf $GOPATH/src/k8s.io/kubernetes
go get k8s.io/kubernetes
}
start_e2e_test(){
cd $GOPATH/src/k8s.io/kubernetes/
git checkout $KUBERNETES_VERSION
make test-e2e-node RUNTIME=remote FOCUS="should report resource usage through the stats api" CONTAINER_RUNTIME_ENDPOINT=unix:///var/run/pouchcri.sock
}
install_containerd(){
wget https://github.com/containerd/containerd/releases/download/v1.0.3/containerd-1.0.3.linux-amd64.tar.gz
tar -xzvf containerd-1.0.3.linux-amd64.tar.gz -C /usr/local
rm -rf containerd-1.0.3.linux-amd64.tar.gz
}
install_runc(){
wget https://github.com/opencontainers/runc/releases/download/v1.0.0-rc4/runc.amd64 -P /usr/local/bin
chmod +x /usr/local/bin/runc.amd64
mv /usr/local/bin/runc.amd64 /usr/local/bin/runc
}
#pouch
install_pouch_source(){
mkdir -p $GOPATH/src/github.com/alibaba/
cd $GOPATH/src/github.com/alibaba/
rm -rf pouch
git clone $pouch_github
cd pouch
git fetch --all
git checkout $pouch_github_branch
make build
make install
swapoff -a
free -m
}
start_pouch_bak(){
cd
systemctl daemon-reload
pouchd --enable-cri --cri-version $cri_version > $pouchd_log 2>&1 &
# pouchd --enable-cri --server-tls --tlskey server.key --tlscert server.crt --tlscacert ca.crt> pouchd.log 2>&1 &
}
#kubernetes
setup_repo_ubuntu(){
apt-get update && apt-get install -y apt-transport-https
curl -s $APT_GPG | apt-key add -
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb $APT_SOURCE kubernetes-xenial main
EOF
apt-get update
}
install_kubelet_ubuntu() {
apt-get install -y kubelet=$KUBERNETES_VERSION_UBUNTU kubeadm=$KUBERNETES_VERSION_UBUNTU kubectl=$KUBERNETES_VERSION_UBUNTU
}
setup_repo_centos(){
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
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
}
install_kubelet_centos() {
yum install -y kubelet-$KUBERNETES_VERSION_CENTOS kubeadm-$KUBERNETES_VERSION_CENTOS kubectl-$KUBERNETES_VERSION_CENTOS
systemctl disable firewalld && systemctl stop firewalld
systemctl enable kubelet
}
install_cni_ubuntu() {
apt-get install -y kubernetes-cni
}
install_cni_centos() {
setenforce 0
yum install -y kubernetes-cni
}
config_kubelet() {
cat > /etc/systemd/system/kubelet.service.d/0-pouch.conf <<EOF
[Service]
Environment="KUBELET_EXTRA_ARGS=--container-runtime=remote --container-runtime-endpoint=unix:///var/run/pouchcri.sock --image-service-endpoint=unix:///var/run/pouchcri.sock"
EOF
systemctl daemon-reload
}
config_cni() {
mkdir -p /etc/cni/net.d
cat >/etc/cni/net.d/10-mynet.conf <<-EOF
{
"cniVersion": "0.3.0",
"name": "mynet",
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"subnet": "10.244.1.0/24",
"routes": [
{ "dst": "0.0.0.0/0" }
]
}
}
EOF
cat >/etc/cni/net.d/99-loopback.conf <<-EOF
{
"cniVersion": "0.3.0",
"type": "loopback"
}
EOF
}
start_pouch(){
cat >/etc/systemd/system/pouch.service <<-EOF
{
[Unit]
Description=pouch
[Service]
ExecStart=/usr/local/bin/pouchd --enable-cri
ExecReload=/bin/kill -HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of pouch containers
Delegate=yes
# kill only the pouch process, not all processes in the cgroup
KillMode=process
# restart the pouch process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
}
EOF
systemctl daemon-reload && systemctl restart pouch
}
config_alias(){
echo 'alias repouch="systemctl daemon-reload && systemctl restart pouch"' >> ~/.bashrc
echo "source <(kubectl completion bash)" >> ~/.bashrc
source ~/.bashrc
}
setup_master() {
kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=all --cri-socket=/var/run/pouchcri.sock
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# enable schedule pods on the master node
kubectl taint nodes --all node-role.kubernetes.io/master:NoSchedule-
}
command_exists() {
command -v "$@" > /dev/null 2>&1
}
lsb_dist=''
if command_exists lsb_release; then
lsb_dist="$(lsb_release -si)"
fi
if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
fi
if [ -z "$lsb_dist" ] && [ -r /etc/centos-release ]; then
lsb_dist='centos'
fi
if [ -z "$lsb_dist" ] && [ -r /etc/redhat-release ]; then
lsb_dist='redhat'
fi
if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
lsb_dist="$(. /etc/os-release && echo "$ID")"
fi
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
case "$lsb_dist" in
ubuntu)
if $update_pouch; then
stop_pouch
else
install_tools_ubuntu
install_containerd
install_runc
install_go
fi
setup_path
install_pouch_source
start_pouch
if $e2e_test || $cri_test; then
setup_repo_ubuntu
install_cni_ubuntu
config_cni
setup_path
install_ginkgo
fi
if $e2e_test; then
install_etcd
get_kubernetes
start_e2e_test
fi
if $cri_test; then
install_cri_tools
download_cri_tools
run_cri_validation
fi
if $k8s_cluster; then
setup_repo_ubuntu
install_kubelet_ubuntu
install_cni_ubuntu
if $CONFIG_CNI; then
config_cni
fi
config_kubelet
if $MASTER_NODE; then
setup_master
fi
fi
config_alias
;;
fedora|centos|redhat)
if $update_pouch; then
stop_pouch
else
install_tools
install_containerd
install_runc
install_go
fi
setup_path
install_pouch_source
start_pouch
if $e2e_test || $cri_test; then
setup_repo_centos
install_cni_centos
config_cni
setup_path
install_ginkgo
fi
if $e2e_test; then
install_etcd
get_kubernetes
start_e2e_test
fi
if $cri_test; then
install_cri_tools
download_cri_tools
run_cri_validation
fi
if $k8s_cluster; then
setup_repo_centos
install_kubelet_centos
install_cni_centos
if $CONFIG_CNI; then
config_cni
fi
config_kubelet
if $MASTER_NODE; then
setup_master
fi
fi
;;
*)
echo "$lsb_dist is not supported (not in centos|ubuntu)"
;;
esac