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

A k0s binary compressed with upx won't start #5468

Open
mauromorales opened this issue Jan 23, 2025 · 3 comments
Open

A k0s binary compressed with upx won't start #5468

mauromorales opened this issue Jan 23, 2025 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@mauromorales
Copy link

Hi k0s maintainers, I'm trying to reduce the size of the k0s binary as we do with other Go binaries we put in our images. This is because space can be crucial to some of our users. When I try to do this with k0s, it unfortunately doesn't run the controller any longer. I'm aware this is not k0s fault per se, but I was wondering if you have an idea why. Thanks!

For compression, I use https://github.com/upx/upx in the following way

root@localhost:~# upx -1 /usr/local/bin/k0s
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2024
UPX 4.2.2       Markus Oberhumer, Laszlo Molnar & John Reiser    Jan 3rd 2024

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
 261095805 -> 196392612   75.22%   linux/amd64   k0s

Packed 1 file.

which as mentioned previously takes a 250M binary

root@localhost:~# ls -lash /usr/local/bin/k0s
250M -rwxr-xr-x 1 root root 250M Jan 23 08:07 /usr/local/bin/k0s

down to aprox 188M

root@localhost:~# ls -lash /usr/local/bin/k0s
188M -rwxr-xr-x 1 root root 188M Jan 23 08:01 /usr/local/bin/k0s

However, after doing this, I can no longer start the controller because it breaks with the following error:

k0s controller --single --verbose --debug
...
INFO[2025-01-23 08:02:24] initializing Etcd
INFO[2025-01-23 08:02:24] initializing APIServer
INFO[2025-01-23 08:02:24] initializing Dummy
INFO[2025-01-23 08:02:24] initializing Manager
INFO[2025-01-23 08:02:24] initializing CSRApprover
INFO[2025-01-23 08:02:24] initializing Status
INFO[2025-01-23 08:02:24] initializing EtcdMemberReconciler
INFO[2025-01-23 08:02:24] Staging '/var/lib/k0s/bin/kube-apiserver'
DEBU[2025-01-23 08:02:24] bin/kube-apiserver.gz is at offset 59880115
INFO[2025-01-23 08:02:24] Staging '/var/lib/k0s/bin/etcd'
INFO[2025-01-23 08:02:24] Listening address /run/k0s/status.sock        component=status
DEBU[2025-01-23 08:02:24] bin/etcd.gz is at offset 24935517
Error: failed to create gzip reader for '/var/lib/k0s/bin/kube-apiserver': gzip: invalid header
@twz123 twz123 added the question Further information is requested label Jan 23, 2025
@twz123 twz123 self-assigned this Jan 23, 2025
@twz123
Copy link
Member

twz123 commented Jan 23, 2025

Unfortunately, you cannot upx-compress k0s after the fact. This is because k0s is "sort of" a self-extracting tarball. It has gzipped files attached to the ELF/PE executable. If that executable is mangled by UPX, the offsets will be different, and k0s won't be able to uncompress the embedded binaries.

However, if UPX would be included in k0s's build process, at a stage before the amalgamation, it might work. I'm currently having a look at that ...

@twz123
Copy link
Member

twz123 commented Jan 24, 2025

Alright. The linked PR shows that k0s can in principle be UPX-compressed. Whether this should be the default for the prebuilt binaries on the GitHub release pages needs more thought, though, as the compression is not free. There are runtime caveats that may be more or less important depending on the scenario.

@mauromorales would you be interested in joining the k0s community call next Tuesday? We'd love to learn more about k0s in Kairos and see where we can help. Maybe we can discuss a solution for UPX compression as well: https://dateful.com/eventlink/2735919704

@mauromorales
Copy link
Author

@twz123 Thanks for the explanation and for putting some work on it. I've added the event to my calendar, looking forward to it

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

No branches or pull requests

2 participants