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

[Carry 2535] rootless: support detach-netns mode #2723

Merged
merged 4 commits into from
Jan 31, 2024

Conversation

AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Jan 1, 2024

When RootlessKit v2.0 (rootless-containers/rootlesskit#379) is installed, containerd-rootless.sh launches it with --detach-netns so as to run the daemon in the host network namespace.

This will enable:

  • Accelerated (and deflaked) nerdctl pull, nerdctl push, nerdctl build, etc
  • Proper support for nerdctl pull 127.0.0.1:.../...
  • Proper support for nerdctl run --net=host

Replaces Fahed Dorgaa's PR #2535
Fixes #814
Fixes #86


Note

Rootless containerd recognizes the following environment variables to configure the behavior of RootlessKit:

  • ...
  • CONTAINERD_ROOTLESS_ROOTLESSKIT_DETACH_NETNS=(auto|true|false): whether to launch rootlesskit with the "detach-netns" mode.
    Defaults to "auto", which is resolved to "true" if RootlessKit >= 2.0 is installed.
    The "detached-netns" mode accelerates nerdctl (pull|push|build) and enables nerdctl run --net=host,
    however, there is a relatively minor drawback with BuildKit prior to v0.13:
    the host loopback IP address (127.0.0.1) is exposed to Dockerfile's "RUN" instructions during nerdctl build (not nerdctl run).
    The drawback is fixed in BuildKit v0.13. Upgrading from a prior version of BuildKit needs removing the old systemd unit:
    containerd-rootless-setuptool.sh uninstall-buildkit && rm -f ~/.config/buildkit/buildkitd.toml

To set these variables, create ~/.config/systemd/user/containerd.service.d/override.conf as follows:

[Service]
Environment=CONTAINERD_ROOTLESS_ROOTLESSKIT_DETACH_NETNS="false"

And then run the following commands:

systemctl --user daemon-reload
systemctl --user restart containerd

https://github.com/containerd/nerdctl/blob/main/docs/rootless.md

@AkihiroSuda

This comment was marked as resolved.

@AkihiroSuda AkihiroSuda force-pushed the detach-netns branch 2 times, most recently from b0df933 to 18acfa9 Compare January 2, 2024 00:35
@AkihiroSuda

This comment was marked as resolved.

@AkihiroSuda AkihiroSuda force-pushed the detach-netns branch 3 times, most recently from 79513ca to fd56c62 Compare January 4, 2024 06:15
@AkihiroSuda

This comment was marked as resolved.

@AkihiroSuda AkihiroSuda force-pushed the detach-netns branch 2 times, most recently from 3d57868 to fd2ed9c Compare January 4, 2024 07:30
# The "detached-netns" mode accelerates `nerdctl (pull|push|build)` and enables `nerdctl run --net=host`,
# however, there is a relatively minor drawback with the current version of BuildKit:
# the host loopback IP address (127.0.0.1) is exposed to Dockerfile's "RUN" instructions during `nerdctl build` (not `nerdctl run`).
# If you want to hide 127.0.0.1 from "RUN" instructions, you should set CONTAINERD_ROOTLESS_ROOTLESSKIT_DETACH_NETNS to "false".
Copy link
Member Author

Choose a reason for hiding this comment

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

@containerd/nerdctl-maintainers

This is kinda breaking change.
Let me know we should release this as "nerdctl v2.0" (ahead of containerd v2.0), or we can just stick to "nerdctl v1.8".
I'm leaning toward to the former one.

Copy link
Member

Choose a reason for hiding this comment

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

nerdctl v2.0

SGTM

Copy link
Member

Choose a reason for hiding this comment

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

nerdctl v2.0

SGTM

docs/rootless.md Outdated Show resolved Hide resolved
# The "detached-netns" mode accelerates `nerdctl (pull|push|build)` and enables `nerdctl run --net=host`,
# however, there is a relatively minor drawback with the current version of BuildKit:
# the host loopback IP address (127.0.0.1) is exposed to Dockerfile's "RUN" instructions during `nerdctl build` (not `nerdctl run`).
# If you want to hide 127.0.0.1 from "RUN" instructions, you should set CONTAINERD_ROOTLESS_ROOTLESSKIT_DETACH_NETNS to "false".
Copy link
Member

Choose a reason for hiding this comment

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

nerdctl v2.0

SGTM

pkg/cmd/container/create.go Outdated Show resolved Hide resolved
var addrs []net.Addr
if err := rootlessutil.WithDetachedNetNSIfAny(func() error {
var err2 error
addrs, err2 = net.InterfaceAddrs()
Copy link
Member

Choose a reason for hiding this comment

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

Ah, I think this is what I was missing in my PR; I wasn't pointing to the right IP addresses, right? It's not an issue with runc as we discussed in Chicago.

@fahedouch
Copy link
Member

thanks @AkihiroSuda

LGTM overall, just this small typo

Thanks again for taking the time to address this feature

@AkihiroSuda
Copy link
Member Author

Will rebase when BuildKit v0.13 beta2 is released

AkihiroSuda and others added 3 commits January 31, 2024 14:43
Signed-off-by: Akihiro Suda <[email protected]>
When RootlessKit v2.0 (rootless-containers/rootlesskit PR 379) is
installed, `containerd-rootless.sh` launches it with `--detach-netns`
so as to run the daemon in the host network namespace.

This will enable:
- Accelerated (and deflaked) `nerdctl pull`, `nerdctl push`, `nerdctl build`, etc
- Proper support for `nerdctl pull 127.0.0.1:.../...`
- Proper support for `nerdctl run --net=host`

Replaces Fahed Dorgaa's PR 2535

Co-authored-by: fahed dorgaa <[email protected]>
Signed-off-by: Akihiro Suda <[email protected]>
@AkihiroSuda AkihiroSuda merged commit 9102092 into containerd:main Jan 31, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants