diff options
author | Pouria Rezaei <Pouria.rz@outlook.com> | 2024-06-24 22:10:37 +0700 |
---|---|---|
committer | Willy Sudiarto Raharjo <willysr@slackbuilds.org> | 2024-06-24 22:17:10 +0700 |
commit | 4690047eb9257611f1f802f1421bfcc14d35597c (patch) | |
tree | 0301dbb3ebce632502c9ff70ac512e2d166a882e /system | |
parent | 43b1c368a24b15f78f11ba566fd200bbf70479b6 (diff) |
system/k3s: Added (Lightweight Kubernetes).
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
Diffstat (limited to 'system')
-rw-r--r-- | system/k3s/README | 18 | ||||
-rw-r--r-- | system/k3s/config/k3s.service.env | 10 | ||||
-rw-r--r-- | system/k3s/config/rc.k3s | 139 | ||||
-rw-r--r-- | system/k3s/doinst.sh | 18 | ||||
-rw-r--r-- | system/k3s/k3s.SlackBuild | 100 | ||||
-rw-r--r-- | system/k3s/k3s.info | 10 | ||||
-rw-r--r-- | system/k3s/slack-desc | 19 |
7 files changed, 314 insertions, 0 deletions
diff --git a/system/k3s/README b/system/k3s/README new file mode 100644 index 0000000000000..0a6cd3b56bfe7 --- /dev/null +++ b/system/k3s/README @@ -0,0 +1,18 @@ +k3s (Lightweight Kubernetes Distribution) + +k3s is a lightweight, fully compliant Kubernetes distribution designed +for constrained environments such as edge computing, IoT devices, and +development setups. Created by Rancher Labs, k3s aims to simplify the +deployment and management of Kubernetes clusters. + + +The following can be used to start/stop k3s automatically: +/etc/rc.d/rc.k3s + if [ -x /etc/rc.d/rc.k3s ]; then + /etc/rc.d/rc.k3s start + fi + +/etc/rc.d/rc.local_shutdown + if [ -x /etc/rc.d/rc.k3s ]; then + /etc/rc.d/rc.k3s stop + fi diff --git a/system/k3s/config/k3s.service.env b/system/k3s/config/k3s.service.env new file mode 100644 index 0000000000000..3fb789499b691 --- /dev/null +++ b/system/k3s/config/k3s.service.env @@ -0,0 +1,10 @@ +# K3S_EXEC= +# K3S_TOKEN= +# K3S_AGENT_TOKEN= +# K3S_CONFIG_FILE=/etc/rancher/k3s/config.yaml +# K3S_TOKEN_FILE=/var/lib/rancher/k3s/server/token +# K3S_AGENT_TOKEN_FILE=/var/lib/rancher/k3s/server/agent-token + +# HTTP_PROXY=http://your-proxy.example.com:8888 +# HTTPS_PROXY=http://your-proxy.example.com:8888 +# NO_PROXY=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
\ No newline at end of file diff --git a/system/k3s/config/rc.k3s b/system/k3s/config/rc.k3s new file mode 100644 index 0000000000000..3cfeed1b5c253 --- /dev/null +++ b/system/k3s/config/rc.k3s @@ -0,0 +1,139 @@ +#!/usr/bin/env bash + +### BEGIN INIT INFO +# Provides: k3s +# Required-Start: $network $remote_fs $syslog +# Required-Stop: $network $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Lightweight Kubernetes Distribution +### END INIT INFO + +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin + +BASE=k3s +DAEMON_DIR=/usr/bin +DAEMON="$BASE server" +PID=/var/run/$BASE.pid +SOCK=/run/k3s/containerd/containerd.sock +ENVFILE=/etc/rancher/$BASE/$BASE.service.env + +# Load environment variables +[ -r $ENVFILE ] && . $ENVFILE + +do_start() { + # Load kernel modules + /sbin/modprobe br_netfilter || true + /sbin/modprobe overlay || true + + $DAEMON_DIR/$DAEMON > /dev/null 2>&1 & + pidof "$DAEMON" > $PID + + sleep 7 + if [ -f $PID ]; then + echo "$BASE has started." + else + echo "$BASE failed to start. Please restart the daemon." + fi +} + +do_stop() { + if [ -f $PID ]; then + echo "Stopping $BASE.." + kill $(ps aux | grep "$SOCK" | awk '{print $2}') \ + $(cat $PID) > /dev/null 2>&1 + sleep 2 + ip link delete flannel.1 > /dev/null 2>&1 + rm -f $PID + echo "$BASE has stopped." + else + killall "$DAEMON" > /dev/null 2>&1 || echo "$BASE is not running." + fi +} + +do_restart() { + do_stop > /dev/null + do_start > /dev/null + echo "$BASE has restarted." +} + +do_stat() { + if [ -s $PID ]; then + echo "$BASE is running: $(cat $PID)" + else + echo "$BASE is not running." + fi +} + +case "$1" in + start) + echo "Starting $BASE.." + do_start + ;; + stop) + do_stop + ;; + killall) + # This option is merged from killall script, good idea to have it here! + echo "Stopping $BASE and cleaning up resources.." + if [ ! -f $PID ]; then + do_start > /dev/null + fi + sleep 5 + pschildren() { + ps -e -o ppid= -o pid= | \ + sed -e 's/^\s*//g; s/\s\s*/\t/g;' | \ + grep -w "^$1" | \ + cut -f2 + } + pstree() { + for pid in $@; do + echo $pid + for child in $(pschildren $pid); do + pstree $child + done + done + } + killtree() { + kill -9 $( + { set +x; } 2>/dev/null; + pstree $@; + set -x; + ) 2>/dev/null + } + getshims() { + ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1 + } + killtree $({ set +x; } 2>/dev/null; getshims; set -x) + do_unmount_and_remove() { + awk -v path="$1" '$2 ~ ("^" path) { print $2 }' /proc/self/mounts | sort -r | xargs -r -t -n 1 sh -c 'umount "$0" && rm -rf "$0"' + } + sleep 2 + do_unmount_and_remove '/run/k3s' + do_unmount_and_remove '/var/lib/rancher/k3s' + do_unmount_and_remove '/var/lib/kubelet/pods' + do_unmount_and_remove '/run/netns/cni-' + ip netns show 2>/dev/null | grep cni- | xargs -r -t -n 1 ip netns delete + ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do + iface=${iface%%@*} + [ -z "$iface" ] || ip link delete $iface + done + ip link delete cni0 + ip link delete flannel.1 + rm -rf /var/lib/cni/ + iptables-save | grep -v 'KUBE-\|CNI-' | iptables-restore + do_stop > /dev/null + echo "Done." + ;; + status) + do_stat + ;; + restart) + echo "Restarting $BASE.." + do_restart + ;; + *) + echo "Usage: $0 {start|stop|killall|status|restart}" >&2 + exit 1 + ;; +esac
\ No newline at end of file diff --git a/system/k3s/doinst.sh b/system/k3s/doinst.sh new file mode 100644 index 0000000000000..05261ffff7330 --- /dev/null +++ b/system/k3s/doinst.sh @@ -0,0 +1,18 @@ +config() { + NEW="$1" + OLD="$(dirname $NEW)/$(basename $NEW .new)" + # If there's no config file by that name, mv it over: + if [ ! -r $OLD ]; then + mv $NEW $OLD + elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then + # toss the redundant copy + rm $NEW + fi + # Otherwise, we leave the .new copy for the admin to consider... +} + +config etc/rancher/k3s/k3s.service.env.new + +if [ -x /etc/rc.d/rc.k3s ]; then + /etc/rc.d/rc.k3s restart > /dev/null +fi diff --git a/system/k3s/k3s.SlackBuild b/system/k3s/k3s.SlackBuild new file mode 100644 index 0000000000000..02bd7a072d96c --- /dev/null +++ b/system/k3s/k3s.SlackBuild @@ -0,0 +1,100 @@ +#!/bin/bash + +# Slackware build script for K3S + +# Copyright 2019-2024 Pouria Rezaei <Pouria.rz@outlook.com> +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +cd $(dirname $0) ; CWD=$(pwd) + +PRGNAM=k3s +VERSION=${VERSION:-1.30.0} +BUILD=${BUILD:-1} +TAG=${TAG:-_SBo} +PKGTYPE=${PKGTYPE:-tgz} + +if [ -z "$ARCH" ]; then + case "$( uname -m )" in + i?86) ARCH=i586 ;; + arm*) ARCH=arm ;; + *) ARCH=$( uname -m ) ;; + esac +fi + +if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then + echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE" + exit 0 +fi + +TMP=${TMP:-/tmp/SBo} +PKG=$TMP/package-$PRGNAM +OUTPUT=${OUTPUT:-/tmp} + +set -e + +if [ "$ARCH" = "i586" ]; then + DEBARCH="i386" +elif [ "$ARCH" = "i686" ]; then + DEBARCH="i386" +elif [ "$ARCH" = "x86_64" ]; then + DEBARCH="amd64" +else + echo "Package for $ARCH architecture is not available." + exit 1 +fi + +rm -rf $PKG +mkdir -p $TMP $PKG $OUTPUT +cd $TMP +rm -rf $PRGNAM-$VERSION +mkdir -p $PRGNAM-$VERSION + +cd $PKG + +mkdir -p usr/bin +install -m 0755 $CWD/$PRGNAM usr/bin/$PRGNAM + +mkdir -p etc/rc.d +install -m 0644 $CWD/config/rc.k3s etc/rc.d/rc.k3s + +mkdir -p etc/rancher/$PRGNAM +install -m 0644 $CWD/config/k3s.service.env etc/rancher/k3s/k3s.service.env.new + +chown -R root:root . +find -L . \ +\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \ +-o -perm 511 \) -exec chmod 755 {} \; -o \ +\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \ +-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \; + +for symlink in kubectl crictl ctr; do + ln -sf /usr/bin/k3s usr/bin/$symlink +done + +rm -rf usr/share/doc +mkdir -p usr/doc/$PRGNAM-$VERSION +cat $CWD/$PRGNAM.SlackBuild > usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild + +mkdir -p install +cat $CWD/slack-desc > install/slack-desc +cat $CWD/doinst.sh > install/doinst.sh + +cd $PKG +/sbin/makepkg -l y -p -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE diff --git a/system/k3s/k3s.info b/system/k3s/k3s.info new file mode 100644 index 0000000000000..5a91c9ccd6437 --- /dev/null +++ b/system/k3s/k3s.info @@ -0,0 +1,10 @@ +PRGNAM="k3s" +VERSION="1.30.0" +HOMEPAGE="https://k3s.io/" +DOWNLOAD="UNSUPPORTED" +MD5SUM="" +DOWNLOAD_x86_64="https://github.com/k3s-io/k3s/releases/download/v1.30.0+k3s1/k3s" +MD5SUM_x86_64="0cada93485b76e3159cf6456248f09dc" +REQUIRES="" +MAINTAINER="Pouria Rezaei" +EMAIL="Pouria.rz@outlook.com" diff --git a/system/k3s/slack-desc b/system/k3s/slack-desc new file mode 100644 index 0000000000000..c25d7b819d610 --- /dev/null +++ b/system/k3s/slack-desc @@ -0,0 +1,19 @@ +# HOW TO EDIT THIS FILE: +# The "handy ruler" below makes it easier to edit a package description. +# Line up the first '|' above the ':' following the base package name, and +# the '|' on the right side marks the last column you can put a character in. +# You must make exactly 11 lines for the formatting to be correct. It's also +# customary to leave one space after the ':' except on otherwise blank lines. + + |-----handy-ruler------------------------------------------------------| +k3s: k3s (Lightweight Kubernetes Distribution) +k3s: +k3s: k3s is a lightweight, fully compliant Kubernetes distribution designed +k3s: for constrained environments such as edge computing, IoT devices, and +k3s: development setups. Created by Rancher Labs, k3s aims to simplify the +k3s: deployment and management of Kubernetes clusters. +k3s: +k3s: +k3s: URL: https://k3s.io/ +k3s: +k3s: |