Skip to content

Commit afdc3a3

Browse files
committed
feature: add allinone to deploy pouch as available container to kubernetes
Signed-off-by: Zou Rui <[email protected]>
1 parent d4b155a commit afdc3a3

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

hack/kubernetes/allinone.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/bash
2+
3+
# This file allows you to init kuberenete master node with pouch containers available.
4+
# Ubuntu and CentOS supported.
5+
6+
set -o errexit
7+
set -o nounset
8+
9+
KUBERNETES_VERSION_UBUNTU="1.9.4-00"
10+
KUBERNETES_VERSION_CENTOS="1.9.4"
11+
MASTER_CIDR="10.244.1.0/24"
12+
13+
install_pouch_ubuntu() {
14+
sudo apt-get install lxcfs
15+
sudo apt-get install curl apt-transport-https ca-certificates software-properties-common
16+
curl -fsSL http://mirrors.aliyun.com/opsx/pouch/linux/debian/[email protected] | sudo apt-key add -
17+
sudo add-apt-repository "deb http://mirrors.aliyun.com/opsx/pouch/linux/debian/ pouch stable"
18+
sudo apt-get update
19+
sudo apt-get install pouch
20+
sudo service pouch start
21+
}
22+
23+
install_pouch_centos() {
24+
sudo yum install -y yum-utils
25+
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/opsx/opsx-centos7.repo
26+
sudo yum update
27+
sudo yum install pouch
28+
sudo systemctl start pouch
29+
}
30+
31+
install_kubelet_ubuntu() {
32+
apt-get update && apt-get install -y apt-transport-https
33+
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
34+
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
35+
deb http://apt.kubernetes.io/ kubernetes-xenial main
36+
EOF
37+
apt-get update
38+
apt-get install -y kubelet=$KUBERNETES_VERSION_UBUNTU kubeadm=$KUBERNETES_VERSION_UBUNTU kubectl=$KUBERNETES_VERSION_UBUNTU
39+
}
40+
41+
install_kubelet_centos() {
42+
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
43+
[kubernetes]
44+
name=Kubernetes
45+
baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
46+
enabled=1
47+
gpgcheck=1
48+
repo_gpgcheck=1
49+
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
50+
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
51+
EOF
52+
yum install -y kubelet-$KUBERNETES_VERSION_CENTOS kubeadm-$KUBERNETES_VERSION_CENTOS kubectl-$KUBERNETES_VERSION_CENTOS
53+
systemctl disable firewalld && systemctl stop firewalld
54+
systemctl enable kubelet
55+
}
56+
57+
install_cni_ubuntu() {
58+
apt-get install -y kubernetes-cni
59+
}
60+
61+
install_cni_centos() {
62+
setenforce 0
63+
yum install -y kubernetes-cni
64+
}
65+
66+
config_kubelet() {
67+
sed -i '2 i\Environment="KUBELET_EXTRA_ARGS=--container-runtime=remote --container-runtime-endpoint=unix:///var/run/pouchcri.sock --image-service-endpoint=unix:///var/run/pouchcri.sock"' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
68+
systemctl daemon-reload
69+
systemctl start kubelet
70+
}
71+
72+
config_cni() {
73+
mkdir -p /etc/cni/net.d
74+
cat >/etc/cni/net.d/10-mynet.conf <<-EOF
75+
{
76+
"cniVersion": "0.3.0",
77+
"name": "mynet",
78+
"type": "bridge",
79+
"bridge": "cni0",
80+
"isGateway": true,
81+
"ipMasq": true,
82+
"ipam": {
83+
"type": "host-local",
84+
"subnet": "${MASTER_CIDR}",
85+
"routes": [
86+
{ "dst": "0.0.0.0/0" }
87+
]
88+
}
89+
}
90+
EOF
91+
cat >/etc/cni/net.d/99-loopback.conf <<-EOF
92+
{
93+
"cniVersion": "0.3.0",
94+
"type": "loopback"
95+
}
96+
EOF
97+
}
98+
99+
setup_master() {
100+
kubeadm init --skip-preflight-checks
101+
# enable schedule pods on the master node
102+
export KUBECONFIG=/etc/kubernetes/admin.conf
103+
kubectl taint nodes --all node-role.kubernetes.io/master:NoSchedule-
104+
}
105+
106+
command_exists() {
107+
command -v "$@" > /dev/null 2>&1
108+
}
109+
110+
lsb_dist=''
111+
if command_exists lsb_release; then
112+
lsb_dist="$(lsb_release -si)"
113+
fi
114+
if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
115+
lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
116+
fi
117+
if [ -z "$lsb_dist" ] && [ -r /etc/centos-release ]; then
118+
lsb_dist='centos'
119+
fi
120+
if [ -z "$lsb_dist" ] && [ -r /etc/redhat-release ]; then
121+
lsb_dist='redhat'
122+
fi
123+
if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
124+
lsb_dist="$(. /etc/os-release && echo "$ID")"
125+
fi
126+
127+
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
128+
129+
case "$lsb_dist" in
130+
131+
ubuntu)
132+
install_pouch_ubuntu
133+
install_kubelet_ubuntu
134+
install_cni_ubuntu
135+
config_kubelet
136+
config_cni
137+
setup_master
138+
;;
139+
140+
fedora|centos|redhat)
141+
install_pouch_centos
142+
install_kubelet_centos
143+
install_cni_centos
144+
config_kubelet
145+
config_cni
146+
setup_master
147+
;;
148+
149+
*)
150+
echo "$lsb_dist is not supported (not in centos|ubuntu)"
151+
;;
152+
153+
esac

0 commit comments

Comments
 (0)