-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 rootless does not work when run from docker container #2054
Comments
I got a little farther by setting the group of the Using strace, I see the invocation of slirp4netns, which writes an error (that I do not see on the terminal) and exits 1:
|
And farther still after upgrading the But still no dice (even with
|
On the host system, running |
There have been several recent fixes for rootless mode, including the slirp4netns update and |
@brandond Sure. Using Currently stuck on:
Also, what should the snapshotter be? I'm using |
Just out of curiosity, have you tried k3d, or is there some reason in particular you want to manually run rootless in docker? |
I've not looked at k3d in long time. Started there, but moved to our own scripts to run k3s in docker for various reasons. But if k3d supports a rootless mode, then I'll give it another look. |
I don't know that it specifically supports rootless, but I think it's the best way to run k3s in docker. k3s in docker while also rootless is not something that's seen much testing, as far as I'm aware. |
Well those above errors are not fatal it seems. I'm able to run kubectl and start pods, etc. Curiously, I cannot run $ docker exec -ti $container sh
## user "k3s" in the container
$ ctr image ls
ctr: failed to dial "/run/k3s/containerd/containerd.sock": context deadline exceeded
$ ls -l /run/k3s/containerd
ls: cannot access '/run/k3s/containerd': No such file or directory
$ ps -e -o pid,ppid,args | grep containerd
66 49 containerd -c /var/lib/rancher/k3s/agent/etc/containerd/config.toml -a /run/k3s/containerd/containerd.sock --state /run/k3s/containerd --root /var/lib/rancher/k3s/agent/containerd
830 17 /bin/containerd-shim-runc-v2 -namespace k8s.io -id 79b5f37335148f0dc36a13404685ca24b049a4f8da080172c0917c85954a097c -address /run/k3s/containerd/containerd.sock
...
$ nsenter -t 66 -a -- ls /run/k3s/containerd
nsenter: reassociate to namespace 'ns/cgroup' failed: Operation not permitted And I've also not figured out how to connect over the network to any of my pods, but that's a semi-known issue with rootless. |
Entering the container as root (which sort of defeats the whole exercise) does allow me to run $ docker exec --user root -ti $container sh
### root in the container
# ls -l /run/k3s/containerd
ls: cannot access '/run/k3s/containerd': No such file or directory
## root can use nsenter though...
# nsenter -t 66 -a -- ctr images ls
<... expected image list ...> |
I'm a little confused by the fact that you are getting |
Same container. Note it's not root vs. non-root, but whatever the default container's namespace is vs. entering containerd's namespace (both of those shell session were run from inside a (I updated the shell listings to clarify a little) |
To summarize current status: abstractI can launch k3s, run There are various warnings and errors in the logs. I cannot run detailsHere's the image that I'm running. It's k3s built from current master plus the uidmap tools and a "k3s" non-root user. FROM alpine:3.12 AS alpine
RUN apk -u --no-cache add shadow-uidmap
# custom built from k3s source
FROM rancher/k3s:v1.18.6-k3s-4eb88a2f-amd64
COPY --from=alpine /etc/passwd /etc/group /etc/shadow /etc/subgid /etc/subuid /etc/
COPY --from=alpine /usr/bin/newgidmap /usr/bin/newuidmap /usr/bin/
COPY --from=alpine /lib/ld-musl-x86_64.so.1 /lib/
RUN mkdir -p /var/lib/rancher/k3s \
&& adduser -h /var/lib/rancher/k3s -g k3s -s /bin/false -D -u 1001 -G root k3s \
&& echo k3s:165536:65536 >> /etc/subuid \
&& echo k3s:165536:65536 >> /etc/subgid
RUN chmod g+w /bin/aux
RUN echo F3F79821-80EE-4B43-A4DD-E3DA712CA2BC >/etc/machine-id
USER k3s:root I'm not sure the machine id is necessary or best practice, but having one eliminated an error message that got logged repeatedly. I start this container like: $ docker run --privileged -p 6443:6443 -p 80:10080 \
server --rootless --snapshotter native --data-dir /var/lib/rancher/k3s At this point, I can deploy and run my app. I can connect to it from the host machine via port 80 (which goes to 10080 inside the container, which is k3s' network as described in https://rancher.com/docs/k3s/latest/en/advanced/#known-issues-with-rootlesskit From inside the container ( From inside the container, I cannot run $ ctr image ls
ctr: failed to dial "/run/k3s/containerd/containerd.sock": context deadline exceeded In fact I cannot even see that socket: $ ls /run/k3s
ls: cannot access '/run/k3s': No such file or directory Nor can I enter the namespaces of containerd: $ pid=$(ps -e -o comm,pid,ppid,args | grep '^containerd ' | awk '{print $2}')
$ nsenter -t $pid -a -- ls /run/k3s
nsenter: reassociate to namespace 'ns/cgroup' failed: Operation not permitted From inside the container as root, I can enter the namespaces of containerd and run ctr: $ docker exec --user=root -ti $container sh
# pid=$(ps -e -o comm,pid,ppid,args | grep '^containerd ' | awk '{print $2}')
# nsenter -t $pid -a -- ls /run/k3s
containerd
# nsenter -t $pid -a -- ctr images ls | head -n1
REF TYPE DIGEST SIZE PLATFORMS LABELS
docker.io/rancher/coredns-coredns:1.6.9 application/vnd.docker.distribution.manifest.list.v2+json sha256:e70c936deab8efed89db66f04847fec137dbb81d5b456e8068b6e71cb770f6c0 12.8 MiB linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x io.cri-containerd.image=managed
... In the logs of the k3s container, these are repeated over and over but seems mostly harmless:
|
Well it's not perfect, but it does run at this point, so I'm closing this issue. Thanks for your help @brandond. Would appreciate if anyone has tips/suggestions for getting past the error and warning log messages, and/or explaining the namespaces or a way to run |
I needed to update I don't understand why this issue is closed? I think it would be better to fix k3s image, rather hacking around to make it work. |
Rootless is experimental, and not intended to be the default state, either on bare metal or in a container. That's why the default image doesn't run rootless. |
I am probably at the same stage as here. But my log message is a bit different. It basically repeats this two logs every few minutes.
I use my Raspberry 4b (4GB) with Ubuntu 20.04 LTS. Downloaded the |
The two messages you're getting are expected. The first is because Pis do not have CPU topology, the second is because non-root users are not allowed to adjust their OOM score. Are you seeing anything not work? |
Thanks for the reply. For now it looks like everything is working so far despite the various warnings and errors. |
Environmental Info:
K3s Version: k3s version v1.18.6+k3s1 (6f56fa1)
Node(s) CPU architecture, OS, and Version: Linux docker-desktop 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 GNU/Linux
Cluster Configuration: k3s docker container, server and agent running together in same container
Describe the bug:
In rootless mode, the cluster fails with:
Steps To Reproduce:
Expected behavior:
Well I'm not sure. I'd like to be able to run rootless k3s in a docker container, but I'm not sure if this is possible.
Actual behavior:
Additional context / logs:
The text was updated successfully, but these errors were encountered: