Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bake k0s as a systemd sysext image. #99

Closed
wants to merge 3 commits into from
Closed

Conversation

mnbro
Copy link

@mnbro mnbro commented Nov 21, 2024

Bake k0s as a systemd sysext image.

This PR aims to bake k0s as a systemd sysext and also provide a systemd unit file to manage k0s.

How to use

[ describe what reviewers need to do in order to validate this PR ]

Testing done

[Describe the testing you have done before submitting this PR. Please include both the commands you issued as well as the output you got.]

  • Changelog entries added in the respective changelog/ directory (user-facing change, bug fix, security fix, update)
  • Inspected CI output for image differences: /boot and /usr size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.

@mnbro
Copy link
Author

mnbro commented Nov 25, 2024

@tormath1 Can you please take a look and see if we can merge this?

After this is merged it would be nice to align k0s with the latest releases in the same way it was implemented for k3s in #98

Copy link
Contributor

@tormath1 tormath1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, some feedback:

  • do you want some units to be started when the sysext is loaded? If yes, you might need to add this kind of command:
    mkdir -p "${SYSEXTNAME}/usr/lib/systemd/system/multi-user.target.d"
    { echo "[Unit]"; echo "Upholds=containerd.service"; } > "${SYSEXTNAME}/usr/lib/systemd/system/multi-user.target.d/10-containerd-service.conf"
  • could you write some documentation on how to use this sysext (e.g does it need provisioning with Ignition to create files / enable units / etc.)

Comment on lines 20 to 26
# The github release uses different arch identifiers, we map them here
# and rely on bake.sh to map them back to what systemd expects
if [ "${ARCH}" = "amd64" ] || [ "${ARCH}" = "x86-64" ]; then
URL="https://github.com/k0sproject/k0s/releases/download/${VERSION}/k0s-${VERSION}-amd64"
elif [ "${ARCH}" = "arm64" ] || [ "${ARCH}" = "aarch64" ]; then
URL="https://github.com/k0sproject/k0s/releases/download/${VERSION}/k0s-${VERSION}-arm64"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just set the correct ARCH and only assign one URL. Something like that:

Suggested change
# The github release uses different arch identifiers, we map them here
# and rely on bake.sh to map them back to what systemd expects
if [ "${ARCH}" = "amd64" ] || [ "${ARCH}" = "x86-64" ]; then
URL="https://github.com/k0sproject/k0s/releases/download/${VERSION}/k0s-${VERSION}-amd64"
elif [ "${ARCH}" = "arm64" ] || [ "${ARCH}" = "aarch64" ]; then
URL="https://github.com/k0sproject/k0s/releases/download/${VERSION}/k0s-${VERSION}-arm64"
fi
# The github release uses different arch identifiers, we map them here
# and rely on bake.sh to map them back to what systemd expects
if [ "${ARCH}" = "amd64" ] || [ "${ARCH}" = "x86-64" ]; then
ARCH="amd64"
fi
if [ "${ARCH}" = "arm64" ] || [ "${ARCH}" = "aarch64" ]; then
ARCH="arm64"
fi
URL="https://github.com/k0sproject/k0s/releases/download/${VERSION}/k0s-${VERSION}-${ARCH}"

popd

mkdir -p "${SYSEXTNAME}"/usr/local/lib/systemd/system/
cat > "${SYSEXTNAME}"/etc/systemd/system/k0s.service << EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cat > "${SYSEXTNAME}"/etc/systemd/system/k0s.service << EOF
cat > "${SYSEXTNAME}"/usr/local/lib/systemd/system/k0s.service << EOF

/etc content is not applied when the sysext is merged to the OS (only /usr and /opt).

WantedBy=multi-user.target
EOF

cat > "${SYSEXTNAME}"/etc/systemd/system/k0scontroller.service << EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cat > "${SYSEXTNAME}"/etc/systemd/system/k0scontroller.service << EOF
cat > "${SYSEXTNAME}"/usr/local/lib/systemd/system/k0scontroller.service << EOF

Same as above.

WantedBy=multi-user.target
EOF

cat > "${SYSEXTNAME}"/etc/systemd/system/k0sworker.service << EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

create_k0s_sysext.sh Show resolved Hide resolved
@mnbro
Copy link
Author

mnbro commented Nov 25, 2024

Thanks for the PR, some feedback:

  • do you want some units to be started when the sysext is loaded? If yes, you might need to add this kind of command:
    mkdir -p "${SYSEXTNAME}/usr/lib/systemd/system/multi-user.target.d"
    { echo "[Unit]"; echo "Upholds=containerd.service"; } > "${SYSEXTNAME}/usr/lib/systemd/system/multi-user.target.d/10-containerd-service.conf"

There will be no systemd units automatically enabled. As will be written in the documentation:
i. choosing the embedded components of k0s will lead to some systemd units being enabled by the user(via Ignition) -> (k0s.service for controllers and k0sworker.service for workers )

ii. not opting for k0s embedded componets will lead to other systemd units being enabled by the user(via Ignition) ->(k0scontroller.service for controllers and k0sworker.service for workers)

  • could you write some documentation on how to use this sysext (e.g does it need provisioning with Ignition to create files / enable units / etc.)

Ok

@mnbro
Copy link
Author

mnbro commented Nov 26, 2024

@tormath1 I've committed the requested changes. Please take a look.

1. the sysext plus the configuration files /etc/k0s/k0s.yaml and/or /etc/default/k0s
2. the systemd units

After you enable k0s syext following the guide deacribed on Consuming the published images, follow the next steps:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
After you enable k0s syext following the guide deacribed on Consuming the published images, follow the next steps:
After you enabled k0s sysext following the guide described on consuming the published images, follow the next steps:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be pushed with executable mode:

diff --git a/create_k0s_sysext.sh b/create_k0s_sysext.sh
old mode 100644
new mode 100755

EnvironmentFile=-/etc/default/k0s
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/bin/sh -c '[ -n "${CRI_SOCKET}" ] && exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml --cri-socket=${CRI_SOCKET} || exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work:

./create_k0s_sysext.sh: line 41: CRI_SOCKET: unbound variable

You need to escape those values (individually or globally with \EOF)

EnvironmentFile=-/etc/default/k0s
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/bin/sh -c '[ -n "${CRI_SOCKET}" ] && exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml --cri-socket=${CRI_SOCKET} || exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ExecStart=/bin/sh -c '[ -n "${CRI_SOCKET}" ] && exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml --cri-socket=${CRI_SOCKET} || exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml'
ExecStart=/bin/sh -c '[ -n "${CRI_SOCKET}" ] && exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml --cri-socket="${CRI_SOCKET}" || exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml'

(Same for the other units)

EnvironmentFile=-/etc/default/k0s
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/usr/local/bin/k0s worker --cri-socket=$CRI_SOCKET --token-file=/etc/k0s/worker-token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ExecStart=/usr/local/bin/k0s worker --cri-socket=$CRI_SOCKET --token-file=/etc/k0s/worker-token
ExecStart=/usr/local/bin/k0s worker --cri-socket="${CRI_SOCKET}" --token-file=/etc/k0s/worker-token


After you enable k0s syext following the guide deacribed on Consuming the published images, follow the next steps:

1.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this mandatory? One might not know by advance the private IP address.

EnvironmentFile=-/etc/default/k0s
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/bin/sh -c '[ -n "${CRI_SOCKET}" ] && exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml --cri-socket=${CRI_SOCKET} --token-file=/etc/k0s/controller-token|| exec /usr/local/bin/k0s controller --config=/etc/k0s/k0s.yaml --token-file=/etc/k0s/controller-token'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Who's supposed to generate this /etc/k0s/controller-token ?

Should we start the k0s.service before ? If yes, it should be documented.

@mnbro
Copy link
Author

mnbro commented Dec 4, 2024

Adding k0s as a systemdsysext will brake k0sctl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants