This repository has been archived by the owner on May 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsykube.def
253 lines (220 loc) · 6.74 KB
/
sykube.def
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
#
# Sykube image
#
Bootstrap: docker
From: ubuntu:xenial
%environment
export PATH=/opt/go/bin:$PATH
export GOPATH=/opt/gopath
export KUBECONFIG=/etc/kubernetes/admin.conf
%setup
mkdir $SINGULARITY_ROOTFS/etc/sykube
cp --preserve=mode sykube $SINGULARITY_ROOTFS/etc/sykube
cat > $SINGULARITY_ROOTFS/etc/hosts <<EOF
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
%post
apt-get update -y && apt-get install -y --no-install-recommends apt-transport-https ca-certificates curl software-properties-common gnupg2 lsb-release wget
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
apt-get update -y
apt-get install -y --no-install-recommends supervisor iproute2 iputils-ping ethtool ebtables kmod
apt-get install -y --no-install-recommends kubelet=1.16.3-00 kubectl=1.16.3-00 kubeadm=1.16.3-00
apt-get install -y --no-install-recommends squashfs-tools libssl-dev uuid-dev libseccomp-dev libseccomp2
apt-get install -y --no-install-recommends gcc make git pkg-config less cryptsetup
rm -rf /var/log/*
mkdir /etc/supervisor/available.d/
cat > /etc/supervisor/available.d/singularity-cri.conf <<EOF
[program:cri]
command=/usr/local/bin/sycri -v=10
priority=10
autostart=true
startsecs=1
autorestart=true
stdout_logfile=/var/log/singularity-cri.out
stderr_logfile=/var/log/singularity-cri.err
environment=PATH="/usr/local/libexec/singularity/bin:/bin:/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
EOF
ln -s /etc/supervisor/available.d/singularity-cri.conf /etc/supervisor/conf.d/singularity-cri.conf
cat > /etc/supervisor/available.d/kubelet.conf <<EOF
[program:kubelet]
priority=100
command=/usr/bin/kubelet-wrapper
autostart=true
startsecs=10
startretries=360
autorestart=true
stdout_logfile=/var/log/kubelet.out
stderr_logfile=/var/log/kubelet.err
EOF
ln -s /etc/supervisor/available.d/kubelet.conf /etc/supervisor/conf.d/kubelet.conf
cat > /etc/supervisor/available.d/kube-proxy.conf <<EOF
[program:kube-proxy]
command=/usr/bin/kube-proxy-wrapper
autostart=true
startsecs=10
startretries=360
autorestart=true
stdout_logfile=/var/log/kube-proxy.out
stderr_logfile=/var/log/kube-proxy.err
EOF
cat > /usr/bin/kube-proxy-wrapper <<EOF
#!/bin/sh
if [ -f "/etc/kubernetes/admin.conf" ]; then
export KUBECONFIG="/etc/kubernetes/admin.conf"
exec /usr/bin/kubectl proxy --address=10.11.11.2
fi
exit 1
EOF
chmod 755 /usr/bin/kube-proxy-wrapper
cat > /usr/bin/kubelet-wrapper <<EOF
#!/bin/sh
KUBELET_EXTRA_ARGS="--container-runtime=remote --container-runtime-endpoint=/var/run/singularity.sock --image-service-endpoint=/var/run/singularity.sock --fail-swap-on=false"
KUBELET_KUBECONFIG_ARGS="--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
KUBELET_CONFIG_ARGS="--config=/var/lib/kubelet/config.yaml"
exec /usr/bin/kubelet \$KUBELET_KUBECONFIG_ARGS \$KUBELET_CONFIG_ARGS \$KUBELET_EXTRA_ARGS
EOF
chmod 755 /usr/bin/kubelet-wrapper
cat > /usr/bin/service-sup <<EOF
#!/bin/sh
case "\$1" in
disable)
if [ -f "/etc/supervisor/conf.d/\$2.conf" ]; then
rm /etc/supervisor/conf.d/\$2.conf
supervisorctl update
else
echo "no service found for \$2"
exit 1
fi
;;
enable)
if [ -f "/etc/supervisor/available.d/\$2.conf" ]; then
ln -s /etc/supervisor/available.d/\$2.conf /etc/supervisor/conf.d/\$2.conf
supervisorctl update
else
echo "no service found for \$2"
exit 1
fi
;;
*)
echo "usage service-sup enable|disable service"
exit 1
;;
esac
EOF
chmod 755 /usr/bin/service-sup
curl https://dl.google.com/go/go1.12.1.linux-amd64.tar.gz | tar -C /opt -xz
export PATH=/opt/go/bin:$PATH
export GOPATH=/opt/gopath
mkdir -p /opt/gopath
cd /opt
git clone https://github.com/sylabs/singularity-cri -b v1.0.0-beta.6
git clone https://github.com/sylabs/singularity -b v3.4.1
export HOME=/tmp
cd /opt/singularity-cri
make && make install
cd /opt/singularity
./mconfig
make -C builddir
make -C builddir install
unset HOME
cat > /etc/sykube/kubeadm.yml <<EOF
apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
nodeRegistration:
criSocket: /var/run/singularity.sock
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: v1.16.3
networking:
podSubnet: 10.244.0.0/16
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: JoinConfiguration
nodeRegistration:
criSocket: /var/run/singularity.sock
EOF
cat > /etc/sykube/admin-user.yml <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
EOF
cat > /etc/sykube/admin-role.yml <<EOF
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system
EOF
mkdir -p /etc/cni/net.d
apt-get clean
apt-get autoclean
cat > /etc/cni/net.d/00_bridge.conflist <<EOF
{
"cniVersion": "0.3.1",
"name": "bridge",
"plugins": [
{
"type": "loopback"
},
{
"type": "bridge",
"bridge": "cbr0",
"isGateway": true,
"isDefaultGateway": true,
"ipMasq": true,
"capabilities": {"ipRanges": true},
"ipam": {
"type": "host-local",
"routes": [
{
"dst": "0.0.0.0/0"
}
]
}
},
{
"type": "portmap",
"capabilities": {"portMappings": true},
"snat": true
}
]
}
EOF
%startscript
mount -t tmpfs tmpfs -o nosuid,nodev,mode=755 /run
mkdir /run/lock
mkdir /run/flannel
mount -t tmpfs tmpfs -o nosuid,nodev,noexec,relatime,size=5120k /run/lock
mount --make-rshared /
mkdir -p /var/log/supervisor
exec supervisord
%runscript
for p in `pgrep --ns $$ -v`; do
if ls -la /proc/$p/root/lib/modules/`uname -r` >/dev/null 2>&1; then
break
fi
done
dest=`realpath --relative-base="/proc/$p/root" "/usr/local/bin" 2>/dev/null`
if [ ! -z "${dest}" ]; then
if cp --preserve=mode /etc/sykube/sykube "/proc/$p/root/${dest}/sykube"; then
echo "sykube is now installed in ${dest}"
exit
fi
else
echo "could not install sykube in /usr/local/bin"
fi
exit 1