forked from k3s-io/k3s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·165 lines (140 loc) · 3.83 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
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
#!/bin/sh
set -e
info()
{
echo "[INFO] " "$@"
}
fatal()
{
echo "[ERROR] " "$@"
exit 1
}
if [ -z `which curl || true` ]; then
fatal "Can not find curl for downloading files"
fi
if [ -n "$1" ]; then
VERSION=$1
else
info "Finding latest release"
VERSION=`curl -w "%{url_effective}" -I -L -s -S https://github.com/rancher/k3s/releases/latest -o /dev/null | sed -e 's|.*/||'`
fi
info "Using $VERSION as release"
ARCH=`uname -m`
case $ARCH in
amd64)
ARCH=amd64
SUFFIX=
;;
x86_64)
ARCH=amd64
SUFFIX=
;;
arm64)
ARCH=arm64
SUFFIX=-${ARCH}
;;
aarch64)
ARCH=arm64
SUFFIX=-${ARCH}
;;
arm*)
ARCH=arm
SUFFIX=-${ARCH}hf
;;
*)
fatal Unknown architecture $ARCH
esac
BINURL=https://github.com/rancher/k3s/releases/download/${VERSION}/k3s${SUFFIX}
HASHURL=https://github.com/rancher/k3s/releases/download/${VERSION}/sha256sum-${ARCH}.txt
if [ -d /run/systemd ]; then
SYSTEMD=true
else
fatal "Can not find systemd to use as a process supervisor for k3s"
fi
SUDO=sudo
if [ `id -u` = 0 ]; then
SUDO=
fi
if [ "$SYSTEMD" = "true" ]; then
info Creating uninstall script /usr/local/bin/k3s-uninstall.sh
TMPUNINSTALL=`mktemp -t k3s-install.XXXXXXXXXX`
cat > $TMPUNINSTALL << "EOF"
#!/bin/sh
set -x
systemctl stop k3s
systemctl disable k3s
systemctl daemon-reload
rm -f /etc/systemd/system/k3s.service
rm -f /usr/local/bin/k3s
if [ -L /usr/local/bin/kubectl ]; then
rm -f /usr/local/bin/kubectl
fi
if [ -L /usr/local/bin/crictl ]; then
rm -f /usr/local/bin/crictl
fi
if [ -e /sys/fs/cgroup/systemd/system.slice/k3s.service/cgroup.procs ]; then
kill -9 `cat /sys/fs/cgroup/systemd/system.slice/k3s.service/cgroup.procs`
fi
umount `cat /proc/self/mounts | awk '{print $2}' | grep '^/run/k3s'`
umount `cat /proc/self/mounts | awk '{print $2}' | grep '^/var/lib/rancher/k3s'`
rm -rf /var/lib/rancher/k3s
rm -rf /etc/rancher/k3s
rm -f /usr/local/bin/k3s-uninstall.sh
EOF
chmod 755 $TMPUNINSTALL
$SUDO chown root:root $TMPUNINSTALL
$SUDO mv -f $TMPUNINSTALL /usr/local/bin/k3s-uninstall.sh
TMPHASH=`mktemp -t k3s-install.XXXXXXXXXX`
TMPBIN=`mktemp -t k3s-install.XXXXXXXXXX`
info Downloading $HASHURL
curl -o $TMPHASH -sfL $HASHURL
info Downloading $BINURL
curl -o $TMPBIN -sfL $BINURL
info Verifying download
EXPECTED=`grep k3s $TMPHASH | awk '{print $1}'`
ACTUAL=`sha256sum $TMPBIN | awk '{print $1}'`
rm -f $TMPHASH
if [ "$EXPECTED" != "$ACTUAL" ]; then
rm -f $TMPBIN
fatal "Download sha256 does not match ${EXPECTED} got ${ACTUAL}"
fi
chmod 755 $TMPBIN
info Installing k3s to /usr/local/bin/k3s
$SUDO chown root:root $TMPBIN
$SUDO mv -f $TMPBIN /usr/local/bin/k3s
if [ ! -e /usr/local/bin/kubectl ]; then
info Creating /usr/local/bin/kubectl symlink to k3s
$SUDO ln -s k3s /usr/local/bin/kubectl
fi
if [ ! -e /usr/local/bin/crictl ]; then
info Creating /usr/local/bin/crictl symlink to k3s
$SUDO ln -s k3s /usr/local/bin/crictl
fi
info systemd: Creating /etc/systemd/system/k3s.service
$SUDO tee /etc/systemd/system/k3s.service >/dev/null << "EOF"
[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
After=network.target
[Service]
Type=notify
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s server
KillMode=process
Delegate=yes
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
[Install]
WantedBy=multi-user.target
EOF
info systemd: Enabling k3s unit
$SUDO systemctl enable k3s.service >/dev/null
$SUDO systemctl daemon-reload >/dev/null
info systemd: Starting k3s
$SUDO systemctl start k3s.service
else
fatal "Can not find systemd"
fi