-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathstart-k3s.sh
80 lines (64 loc) · 1.44 KB
/
start-k3s.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
#!/bin/bash
child=0
sig_handler() {
sig_send=$1
code=$2
if [ $child -ne 0 ]; then
kill -$sig_send $child
wait $child
fi
exit $code
}
trap 'sig_handler HUP 129' HUP
trap 'sig_handler TERM 130' INT
trap 'sig_handler TERM 131' QUIT
trap 'sig_handler TERM 143' TERM
K3S_LOG="/var/log/k3s.log"
function dockerReady {
docker info >& /dev/null
}
function runDocker {
dockerd \
--host=unix:///var/run/docker.sock \
--host=tcp://0.0.0.0:2375 \
> /var/log/docker.log 2>&1 < /dev/null &
until dockerReady ; do
sleep 1
done
}
K3S_NAME=$(hostname)
K3S_ARGS=( \
--no-deploy=traefik \
--docker \
--https-listen-port=${K3S_API_PORT:-8443} \
--node-name=${K3S_NAME} \
--tls-san=${K3S_NAME} \
)
function runServer {
k3s server "${K3S_ARGS[@]}" >> ${K3S_LOG} 2>&1 &
}
function getKubeconfig {
local cfg=$(cat /etc/rancher/k3s/k3s.yaml)
if [[ $cfg =~ password ]]; then
echo "${cfg}" | sed 's/\/\/127.0.0.1:/\/\/'"${K3S_NAME}"':/'
fi
}
function waitForKubeconfig {
local cfg=""
while [ -z "${cfg}" ]; do
sleep 1
cfg=$(getKubeconfig)
done
echo "${cfg}" > /tmp/kubeconfig
mv /tmp/kubeconfig /kubeconfig
}
echo > ${K3S_LOG}
tail -F ${K3S_LOG} &
child=$!
runDocker
runServer
waitForKubeconfig
touch /minikube_startup_complete
echo Kubeconfig is ready
# Put the tail of logs in the foreground to keep the container running
wait $child