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

k3s doesn't work with unified cgroups and the docker runtime #111835

Closed
euank opened this issue Feb 3, 2021 · 11 comments · Fixed by #118801
Closed

k3s doesn't work with unified cgroups and the docker runtime #111835

euank opened this issue Feb 3, 2021 · 11 comments · Fixed by #118801
Labels
0.kind: bug Something is broken 6.topic: k3s Kubernates distribution (https://k3s.io/)

Comments

@euank
Copy link
Member

euank commented Feb 3, 2021

Describe the bug

nixpkgs has moved to unified cgroups (woo 🎉) as of recently (#73800).

Unfortunately, k3s fails to start correctly with unified cgroups without k3s-io/k3s#2844, which isn't included in a release yet.

Until that lands in a release and nixpkgs is updated, it can be worked around by setting systemd.enableUnifiedCgroupHierarchy = false;

I intend to work on fixing this; I'll drop any notes along the way in this issue.

@euank euank added the 0.kind: bug Something is broken label Feb 3, 2021
@euank euank changed the title k3s doesn't work with unified cgroups k3s doesn't work with unified cgroups and the docker runtime Feb 4, 2021
@euank
Copy link
Member Author

euank commented Feb 4, 2021

I've updated the title to be more specific, since my actual errors are coming from using k3s with services.k3s.docker = true;, and the error is specifically about kubelet and docker's cgroup driver mismatching.

I see that the unified cgroup PR did disable unified cgroups in the k3s module, so that probably should work before adding in the docker runtime.
I need to do a little more investigation here.

@pinpox
Copy link
Member

pinpox commented Feb 17, 2021

Please let me know, if this is related:
I'm trying to follow the wiki article on kubernetes on nixos: https://nixos.wiki/wiki/Kubernetes
With the configs shown there I run into an error when starting kubelet.service

failed to run Kubelet: misconfiguration: kubelet cgroup driver: "cgroupfs" is different from docker cgroup driver: "systemd"

The full error is very long, I've uploaded it here: https://gist.github.com/pinpox/4058c540a42d47f456c2e87d5ac3f856

@lbodor
Copy link
Contributor

lbodor commented Feb 18, 2021

Thanks for looking into this.

@pinpox
Copy link
Member

pinpox commented Feb 18, 2021

Just tried the workaround mentioned above: Setting
systemd.enableUnifiedCgroupHierarchy = false; also fixes the problem for the kubernetes service

@imw
Copy link

imw commented Feb 23, 2021

We have observed that unified cgroups also breaks Kubernetes-in-Docker for node images prior to 1.19. The observed behavior is that the kubelet fails to start, with the message:failed to run Kubelet: mountpoint for not found

Also able to work around with systemd.enableUnifiedCgroupHierarchy = false;

@euank
Copy link
Member Author

euank commented Feb 24, 2021

For k3s, the v1.20.4+k3s1 release includes unified cgroups support. It fixes my use of k3s, though I also had to set a flag in the nixos module (--kubelet-arg="cgroup-driver=systemd" to make docker+kubelet match).

I've opened up a PR to bump the package (#114215), and I'll make a separate PR to fix the nixos module to pass that arg.
I think those two changes together should fix this issue.

It sounds like there's other work to be done for other ways of running kubernetes on nixos too, but I think we should open separate issues for those to avoid conflating too many issues at once.

euank added a commit to euank/nixpkgs that referenced this issue Mar 26, 2021
Notably, this includes support for unified cgroups in k3s, which is
especially convenient given nixos has moved to them.

Fixes (at least partly) NixOS#111835
@Mic92
Copy link
Member

Mic92 commented Apr 8, 2021

This would be the fix: #111590
I was not invested enough at the time to also write release notes, but if you want you can pick up the change.

@Mic92
Copy link
Member

Mic92 commented Apr 8, 2021

see #118801

@06kellyjac
Copy link
Member

This PR should also help: k3s-io/k3s#3242

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-setup-kubernetes-k3d-on-nixos/13574/1

euank added a commit to euank/nixpkgs that referenced this issue Jul 19, 2022
Setting `cgroup-driver=systemd` was originally necessary to match with
docker, else the kubelet would not start (NixOS#111835)

However, since then, docker support has been dropped from k3s (NixOS#177790).
As such, this option is much less necessary.

More importantly, it now seems to be actively causing issues. Due to an
upstream k3s bug, it's resulting in the kubelet and containerd having
different cgroup drivers, which seems to result in some difficult to
debug failure modes.

See
NixOS#181790 (comment)
for a description of this problem.

Removing this flag entirely seems reasonable to me, and it results in
k3s working again on my machine.
@superherointj superherointj added the 6.topic: k3s Kubernates distribution (https://k3s.io/) label May 9, 2024
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/declarative-rootless-k3s/49839/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: k3s Kubernates distribution (https://k3s.io/)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants