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

(Option to) create podman containers with --restart=always to restart cluster after reboots #3463

Open
cr opened this issue Dec 26, 2023 · 8 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@cr
Copy link

cr commented Dec 26, 2023

What would you like to be added:

  • Please create podman containers with --restart=always. Landing this behind an option would be fine, too.

At this point, podman containers making up kind clusters have to be re-started manually after reboot with something like podman start --all.

Podman installations typically come with systemd services that stop all containers on system shutdown, but on system boot they only re-start containers with restart policy always (verified for podman on Ubuntu). Since that policy can only be controlled on container creation, the workarounds are rather cumbersome.

This looks somewhat related to #148.

Why is this needed:

  • Managing kind clusters deployed to standalone systems would be significantly streamlined. A rebooted system running a kind cluster (on podman) would be able to come right back up again without user interaction.
@cr cr added the kind/feature Categorizes issue or PR as related to a new feature. label Dec 26, 2023
@aojea
Copy link
Contributor

aojea commented Dec 26, 2023

Podman installations typically come with systemd services that stop all containers on system shutdown, but on system boot they only re-start containers with restart policy always (verified for podman on Ubuntu)

can you send a link to this? last time we checked it was not working

@cr
Copy link
Author

cr commented Dec 26, 2023

There are limitations, but generally it works as described in the podman documentation. The restart service is packaged (and enabled) in Ubuntu and supposedly any Debian-based distro, likely other distros as well.

Here's the relevant service excerpt on a Ubuntu mantic system as seen by # systemctl edit podman-restart.service:

[Service]
Type=oneshot
RemainAfterExit=true
Environment=LOGGING="--log-level=info"
ExecStart=/usr/bin/podman $LOGGING start --all --filter restart-policy=always
ExecStop=/bin/sh -c '/usr/bin/podman $LOGGING stop $(/usr/bin/podman container ls --filter restart-policy=always -q)'

Unfortunately, this only works for podman containers run by root, and currently stopping containers tends to run into timeouts on shutdown. Due to podman's design, even root doesn't see all user containers, so they won't get stopped or started by the systemd service which runs as root by default. It's not too difficult, though, to replicate it as a service running as kind user if running as root is not desired.

@BenTheElder
Copy link
Member

Always works poorly because on a failed cluster startup it will keep retrying indefinitely.

we don't use this policy with the docker runtime, we set one time restart. See the podman tracking issues.

Restart is also going to be problematic without DNS for node names

@cr
Copy link
Author

cr commented Dec 26, 2023

Points taken. I get reliable cluster reboots with a user crontab like

@reboot /usr/bin/podman start --all --filter 'restart-policy=always'
@reboot /usr/bin/podman start --all --filter 'name=kind-.*'

While I agree that it shouldn't be the default, if --restart=always was an option in kind, you could rely on the generic mechanism instead of requiring one crontab line per cluster.

@BenTheElder
Copy link
Member

If we can get restarts working reliably in podman, it will be the default, we don't want to add more knobs or worse container runtime specific knobs.

#2272 is the existing tracking issue for podman.

@starpit
Copy link

starpit commented Jan 29, 2024

a quick echo of the point @cr made. indeed for us a

podman start --all --filter 'name=<our-kind-cluster-name>'

does seem to restore kubernetes functionally after a podman machine restart. it would be nice if this could be generalized? while a kind create cluster -n foo results in a kubernetes context kind-foo, the podman container seems to be named just foo. this leaves us without a general breadcrumb on the container name that would tie it back to kind?

@BenTheElder
Copy link
Member

BenTheElder commented Jan 30, 2024

the podman container seems to be named just foo. this leaves us without a general breadcrumb on the container name that would tie it back to kind?

changing the naming scheme of the containers would break a LOT of stuff (aside: it shouldn't be foo but $name-$node_role$count), but it's already possible to identify cluster containers with kind get nodes -n foo

something like kind get nodes -n foo | xargs podman start ?

@starpit
Copy link

starpit commented Jan 30, 2024

thanks @BenTheElder! i think kind get nodes -A | xargs -n1 podman start might be the general-purpose trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

4 participants