Skip to content

Commit

Permalink
k3s: provide a static k3s binary for edge
Browse files Browse the repository at this point in the history
Signed-off-by: Joe MacDonald <[email protected]>
  • Loading branch information
jjmcdn authored and chombourger committed May 6, 2024
1 parent 94e29e2 commit 68bc83c
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 0 deletions.
3 changes: 3 additions & 0 deletions debian/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
debhelper-build-stamp
files
k3s*
3 changes: 3 additions & 0 deletions debian/README.source
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This package source is managed by quilt. Please refer to
/usr/share/doc/quilt/README.source for details on working
with the quilt patch management system.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
k3s (1.27.2+k3s1+mel1) UNRELEASED; urgency=medium

* local package
* Packaging k3s from meta-virtualization for Sokol Linux

-- Joe MacDonald <[email protected]> Thu, 20 Apr 2023 16:14:13 -0400
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
23 changes: 23 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Source: k3s
Section: admin
Priority: optional
Maintainer: Mentor Embedded <[email protected]>
Build-Depends: debhelper (>= 11), chrpath, cpio, curl, diffstat, docker.io | docker-ce, gawk, lz4, wget, zstd
Standards-Version: 4.5.1
Homepage: https://k3s.io/
Rules-Requires-Root: no

Package: k3s
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, ca-certificates, conntrack-tools, iproute2, ipset, iptables, libc6 (>= 2.37), containerd
Description: Lightweight Kubernetes client binary (k3s)
K3s - Lightweight Kubernetes - is a portable, extensible, open-source
platform for managing containerized workloads and services, that
facilitates both declarative configuration and automation. It has a
large, rapidly growing ecosystem.
.
K3s is fully compliant with Kubernetes distribution that is packaged as a
single binary, providing all dependencies with approximately half the
memory footprint of a full Kubernetes implementation and a binary of
approximately 100MB in size.

21 changes: 21 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: k3s
Upstream-Contact: Derek Nola <[email protected]>

Files: *
Copyright: 2021 K3s Project Authors
License: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
http://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian systems, the complete text of the Apache version 2.0 license
can be found in "/usr/share/common-licenses/Apache-2.0".
78 changes: 78 additions & 0 deletions debian/k3s-killall
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
[ $(id -u) -eq 0 ] || exec sudo $0 $@

for bin in /var/lib/rancher/k3s/data/**/bin/; do
[ -d $bin ] && export PATH=$PATH:$bin:$bin/aux
done

set -x

for service in /etc/systemd/system/k3s*.service; do
[ -s $service ] && systemctl stop $(basename $service)
done

for service in /etc/init.d/k3s*; do
[ -x $service ] && $service stop
done

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() {
set +x
while read -r _ path _; do
case "$path" in $1*) echo "$path" ;; esac
done < /proc/self/mounts | sort -r | xargs -r -t -n 1 sh -c 'umount "$0" && rm -rf "$0"'
set -x
}

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 '/var/lib/kubelet/plugins'
do_unmount_and_remove '/run/netns/cni-'

# Remove CNI namespaces
ip netns show 2>/dev/null | grep cni- | xargs -r -t -n 1 ip netns delete

# Delete network interface(s) that match 'master cni0'
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
ip link delete flannel-v6.1
ip link delete kube-ipvs0
ip link delete flannel-wg
ip link delete flannel-wg-v6
rm -rf /var/lib/cni/
iptables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | iptables-restore
ip6tables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | ip6tables-restore
3 changes: 3 additions & 0 deletions debian/k3s.links
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
usr/sbin/k3s usr/sbin/kubectl
usr/sbin/k3s usr/sbin/crictl
usr/sbin/k3s usr/sbin/ctr
8 changes: 8 additions & 0 deletions debian/k3s.lintian-overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The purpose of the k3s package is to provide a static binary. This static
# linking is intentional, since no dynamic link version is possible.
k3s: statically-linked-binary usr/sbin/k3s
# k3s intentionally does not provide manpages for these.
k3s: no-manual-page usr/sbin/crictl
k3s: no-manual-page usr/sbin/ctr
k3s: no-manual-page usr/sbin/k3s
k3s: no-manual-page usr/sbin/kubectl
27 changes: 27 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/make -f

# output every command that modifies files on the build system.
# export DH_VERBOSE = 1
# make debhelper commands more verbose
# export DH_OPTIONS = -v

%:
dh $@

override_dh_auto_configure:
mkdir -p build/data
make download
make generate

override_dh_auto_test:
@echo Skipping tests

override_dh_auto_install:
mkdir -p debian/k3s/usr/sbin/
mkdir -p debian/k3s/etc/rancher/k3s/
mkdir -p debian/k3s/lib/systemd/system/
install -m 0755 dist/artifacts/k3s debian/k3s/usr/sbin/
ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/kubectl
ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/crictl
ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/ctr
install -m 0644 k3s.service debian/k3s/lib/systemd/system/
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (git)
41 changes: 41 additions & 0 deletions debian/source/lintian-overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# dapper is a build environment used by k3s. It isn't necessary to build the
# source but the makefile provided by the project assumes it will be used and
# will download it as part of the preparation step
source-is-missing .dapper
# These are tools used by dapper to build k3s within docker containers
source-is-missing bin/aux/ebtables-legacy
source-is-missing bin/aux/ebtablesd
source-is-missing bin/aux/ebtablesu
source-is-missing bin/aux/xtables-legacy-multi
source-is-missing bin/aux/xtables-nft-multi
source-is-missing bin/blkid
source-is-missing bin/busybox
source-is-missing bin/cni
source-is-missing bin/conntrack
source-is-missing bin/containerd-shim-runc-v2
source-is-missing bin/coreutils
source-is-missing bin/ethtool
source-is-missing bin/find
source-is-missing bin/fuse-overlayfs
source-is-missing bin/ip
source-is-missing bin/ipset
source-is-missing bin/k3s
source-is-missing bin/losetup
source-is-missing bin/nsenter
source-is-missing bin/pigz
source-is-missing bin/runc
source-is-missing bin/slirp4netns
# this is the output of the full build process, lintian is unable to determine
# this correctly
source-is-missing dist/artifacts/k3s
# the k3s package intentionally provides only a statically linked binary
package-depends-on-hardcoded-libc k3s Depends
package-needs-versioned-debhelper-build-depends 11
# k3s has no Debian maintainer, this is a vendor packaging
no-nmu-in-changelog
# we are using the git source format
unsupported-source-format
# upstream sources aren't part of the git source format
empty-upstream-sources
# this is the formatting used by the k3s.io project for their releases
malformed-debian-changelog-version 1.27.2+k3s1+mel1 (for non-native)

0 comments on commit 68bc83c

Please sign in to comment.