Deepthink R1

1. Update Alpine Linux and Install Edge Kernel (if needed)

If your Alpine version lacks cgroup2 support (common in older releases), enable the Edge repository for newer kernel packages:

echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories
apk update
apk upgrade

2. Install Required Packages

Install tools to manage cgroups:

apk add cgroup-tools

3. Enable cgroup2 Kernel Parameters

Edit /boot/extlinux.conf to add kernel flags for cgroup2:

# Append these parameters to the kernel command line:
cgroup_no_v1=all cgroup_enable=memory cgroup_memory=1

Example modified entry:

APPEND ... rootfstype=ext4 cgroup_no_v1=all cgroup_enable=memory cgroup_memory=1

4. Enable the cgroups Service (OpenRC)

Alpine uses OpenRC to manage services. Enable the cgroups service to auto-mount cgroups at boot:

rc-update add cgroups boot   # Add to boot runlevel
rc-service cgroups start     # Start immediately

5. Reboot the System

Apply kernel changes:

reboot

6. Verify cgroup2 Mount

After reboot, confirm cgroup2 is mounted:

mount | grep cgroup2
# Expected output:
# cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime)

If not mounted, add to /etc/fstab:

echo "none /sys/fs/cgroup cgroup2 defaults 0 0" >> /etc/fstab
mount /sys/fs/cgroup

7. Check Available Controllers

Ensure critical controllers (e.g., memory, cpu) are listed:

cat /sys/fs/cgroup/cgroup.controllers

8. Configure K3s for cgroupfs Driver

Create /etc/rancher/k3s/config.yaml to force K3s to use cgroupfs (required for non-systemd systems):

kubelet-arg:
  - "cgroup-driver=cgroupfs"
containerd:
  extra-args:
    - "--systemd-cgroup=false"

9. Install K3s

Run the installer script:

curl -sfL https://get.k3s.io | sh -

10. Verify K3s (OpenRC)

Check K3s status using OpenRC:

rc-service k3s status
# Start manually if needed:
rc-service k3s start

Troubleshooting

Missing Controllers

If memory or other controllers are missing:

  • Double-check kernel parameters in /boot/extlinux.conf.
  • Reboot and verify with cat /sys/fs/cgroup/cgroup.controllers.

Containerd Configuration

Confirm SystemdCgroup = false in K3s-generated containerd config:

grep "SystemdCgroup" /var/lib/rancher/k3s/agent/etc/containerd/config.toml
# Expected output:
# SystemdCgroup = false

Persistent cgroup Mount

If /sys/fs/cgroup unmounts after reboot:

  • Ensure cgroups service is enabled (rc-update show).
  • Validate /etc/fstab entry for cgroup2.

Why This Works

  • OpenRC Integration: Alpine’s cgroups service handles mounting cgroups at boot.
  • cgroupfs Driver: K3s uses cgroupfs instead of systemd for cgroup management.
  • Edge Kernel: Provides full cgroup2 support (if required).

This setup ensures K3s works seamlessly with cgroup2 on Alpine Linux. Let me know if you run into issues!

This page was last edited on 2025-03-06 18:15

Powered by Wiki|Docs

This page was last edited on 2025-03-06 18:15

Mac
To whom it may concern

Powered by Wiki|Docs