Closed durandx closed 3 years ago
Creating the init containers seems fairly easy, and I think we can order pod startup to ensure that they are the first things to run in the pod without a problem (we already have a built-in startup dependency model), but the behaviour where Kube waits until an init container has cleanly exited to start the next one is problematic - all our dependency ordering is based on the dependency moving to the "running" state, and from a glance at the code this won't be easy to fix.
We'd probably need to add the concept of init containers to Libpod pods, and modify the podman pod start
command to automatically handle this, to make this happen. This does sound useful outside of play kube
so I'm not opposed to doing it this way.
@haircommander Thoughts?
Theoretically, we could spoof init containers on podman side, and not expose to libpod. the work flow could be
though, if you think it'd be useful outside of play kube, exposing to libpod would keep play kube code cleaner
If there's an expectation that init containers run more than once - IE, on each start of the pod - I think libpod is a good place. Kube doesn't really hit this, given they never restart a stopped pod, just recreate, but we will.
We'll also have to modify pod status - a pod where everything except the init containers is running is still a running pod, where I think we'd consider it partially stopped.
If there's an expectation that init containers run more than once - IE, on each start of the pod - I think libpod is a good place. Kube doesn't really hit this, given they never restart a stopped pod, just recreate, but we will.
yeah we'd need to restart the init container process if we restarted the pod
We'll also have to modify pod status - a pod where everything except the init containers is running is still a running pod, where I think we'd consider it partially stopped.
I think a pod state: initializing would be clear for when the init containers are running. I think the containers could be ignored (or they could be cleaned up) in figuring out if the pod is running with little problem
A friendly reminder that this issue had no activity for 30 days.
@haircommander Are you working on this?
I am not currently working on this!
@ryanchpowell Want to take a look?
@rhatdan sounds good, looking into!
This issue is still out there.
@mheon @haircommander @durandx is this still something we should pursue? @zhangguanzhang @Luap99 @saschagrunert WDYT?
How to record the startup sequence of initContainers
A friendly reminder that this issue had no activity for 30 days.
@rhatdan From my part, I think it is still a good idea to have initContainers. One of the use case could be to have a generic container (ex: tomcat) that can be associated with a specific container started with initContainer whose role is to copy, configure and deploy one or more app(s) (ex: my-app.war).
Interested in working on it?
Hello there, I'll follow this one - there's a potential use-case within tripleo/osp for a specific service. The initContainers would prepare the needed configurations and DB before the app actually starts. This feature would allow us to remove a lot of python code and rely on podman itself to manage an ephemeral service.
A friendly reminder that this issue had no activity for 30 days.
Coming up on a year later and no one has worked on this.
Coming up on a year later and no one has worked on this.
How to record the startup sequence of initContainers
Just wonder if any progress here? As @cjeanner mentioned above, it can be a killer feature for TripleO/OSP in Openstack, would help a lot. Thanks.
@mheon would the work you have done on "requires" help with this? IE Could we put requires into a POD, so that we have one of the containers start before the others in the pod?
Sure, you can likely wire this up manually in the CLI now.
You'd basically create the initContainer first, then have every other container in the pod do a --requires <initcontainer>
.
Unfortunately, requires
only guarantees the container was started, not that whatever app inside has successfully run to completion, so there may still be some difficulty there.
I think initContainers should run and finish before any containers start in the pod, at least according to their definition. To @zhangguanzhang question - need to take list of initContainers
in yaml, run them and wait for completion. And only then start all other container(s) in the pod.
I think initContainers should run and finish before any containers start in the pod, at least according to their definition. To @zhangguanzhang question - need to take list of
initContainers
in yaml, run them and wait for completion. And only then start all other container(s) in the pod.
for podman generate kube
, the initContainers' record need from the container's info
for
podman generate kube
, the initContainers' record need from the container's info
Can we start maybe from podman play kube
support?
Probably we can use a flag --initcontainer true
for podman run/create
command to indicate it's an initContainer
for possible kube YAML generation.
I could see podman play kube, looking for init containers, and running them within a pod, and then waiting for them to complete before executing the rest of the containers.
Perhaps we could extend the concept for a POD as well, so that an indicator of an initcontiner means that all of the other containers in the POD would not start until the initcontainer is done.
ISTM that podman play kube
is where this adds the most value. Otherwise, you can simulate it by running the containers sequentially in a script:
# Create empty pod
podman pod create -p 8080:80/tcp --name web
# Run the init container and wait for it to complete
podman run --pod web -v "$PWD":/usr/local/apache2/htdocs/ ubuntu:18.04 \
sh -c "date >/usr/local/apache2/htdocs/index.html; sleep 2"
# Now start the main container
podman run -d --pod web -v "$PWD":/usr/local/apache2/htdocs/ docker.io/library/httpd
# Test
curl localhost:8080
>>> Fri May 14 08:34:12 UTC 2021
However there are issues:
podman rm
)podman pod restart web
restarts both containers simultaneouslySo it would be better if the init container(s) in the pod could be marked for special treatment. Obviously this would also become important if podman were to provide automatic container restarts.
There was a point raised earlier about whether restarting a pod should re-run its init containers or not.
I can see use cases for both scenarios:
On balance, I think the most useful behaviour is always to run the initContainers on pod (re)start. If someone wants an initContainer which doesn't reinitialize a data volume, they can easily check first whether the data is there or not.
This doesn't matter too much given that k8s doesn't support restarting pods anyway, but it might be useful for those running pods under systemd.
A friendly reminder that this issue had no activity for 30 days.
Still no one has worked on this? Any volunteers looking for a good project?
I'll take it ....
Fixes by: https://github.com/containers/podman/pull/11011 /close
@zhangguanzhang: Closing this issue.
/kind feature
A nice feature to have in podman could be handle initContainer in the same way that K8S handle it.
The main problem is that container images and architecture has to be modified between pods in K8s and Podman : K8s can use a dedicated initContainer to properly initialise a pod whereas in podman we have to combine initialisation and core runtime in a single container. This limit the reuse and compatiblity between K8S and podman even for very simple pods.