Skip to content

Commit

Permalink
Merge pull request #69 from johanneskastl/20240426_add_k3s_systemd_unit
Browse files Browse the repository at this point in the history
create_k3s_sysext.sh: create systemd unit files
  • Loading branch information
pothos authored Apr 30, 2024
2 parents 12ac25c + 0f46e4c commit ef4d4a7
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,35 @@ In the [Flatcar docs](https://www.flatcar.org/docs/latest/provisioning/sysext/)

The updates works by [`systemd-sysupdate`](https://www.freedesktop.org/software/systemd/man/sysupdate.d.html) fetching the `SHA256SUMS` file of the generated artifacts, which holds the list of built images with their respective SHA256 digest.

The k3s sysext can be configured by using the following snippet, in case you
want this to be a k3s server (controlplane):

```yaml
variant: flatcar
version: 1.0.0
storage:
links:
- path: /etc/systemd/system/multi-user.target.wants/k3s.service
target: /usr/local/lib/systemd/k3s.service
overwrite: true
```

For a k3s agent (worker node) you would use something like this snippet:

```yaml
variant: flatcar
version: 1.0.0
storage:
links:
- path: /etc/systemd/system/multi-user.target.wants/k3s-agent.service
target: /usr/local/lib/systemd/k3s-agent.service
overwrite: true
```

Of course, any configuration you need should be prepared before starting the
services, like providing a token for an agent or server to join or creating a
`config.yaml` file.

### Creating a custom Docker sysext image

The Docker releases publish static binaries including containerd and the only missing piece are the systemd units.
Expand Down
68 changes: 67 additions & 1 deletion create_k3s_sysext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,71 @@ rm -rf "${SYSEXTNAME}"
mkdir -p "${SYSEXTNAME}"/usr/local/bin
curl -o "${SYSEXTNAME}/usr/local/bin/k3s" -fsSL "${URL}"
chmod +x "${SYSEXTNAME}"/usr/local/bin/k3s
"${SCRIPTFOLDER}"/bake.sh "${SYSEXTNAME}"

mkdir -p "${SYSEXTNAME}"/usr/local/lib/systemd/system/
cat > "${SYSEXTNAME}"/usr/local/lib/systemd/system/k3s.service << EOF
[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
Wants=network-online.target
After=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
Type=notify
EnvironmentFile=-/etc/default/%N
EnvironmentFile=-/etc/sysconfig/%N
EnvironmentFile=-/usr/local/lib/systemd/system/k3s.service.env
KillMode=process
Delegate=yes
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s
ExecStartPre=/bin/sh -xc '! /usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service 2>/dev/null'
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s server
EOF

cat > "${SYSEXTNAME}"/usr/local/lib/systemd/system/k3s-agent.service << EOF
[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
Wants=network-online.target
After=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
Type=notify
EnvironmentFile=-/etc/default/%N
EnvironmentFile=-/etc/sysconfig/%N
EnvironmentFile=-/usr/local/lib/systemd/system/k3s-agent.service.env
KillMode=process
Delegate=yes
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s
ExecStartPre=/bin/sh -xc '! /usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service 2>/dev/null'
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s agent
EOF

RELOAD=1 "${SCRIPTFOLDER}"/bake.sh "${SYSEXTNAME}"
rm -rf "${SYSEXTNAME}"

0 comments on commit ef4d4a7

Please sign in to comment.