containers / podman

Podman: A tool for managing OCI containers and pods.
https://podman.io
Apache License 2.0
23.43k stars 2.38k forks source link

Parallel pod creation with `podman kube play` #24096

Open jennydaman opened 1 week ago

jennydaman commented 1 week ago

Feature request description

The command podman kube play creates pods sequentially, which is different from the behavior of Kubernetes and kubectl which create resources in parallel. This is problematic when one pod is dependent on another, e.g. running PostgreSQL in one pod, and running a backend in a second pod, where the second pod has an initContainer to poll for PostgreSQL's readiness.

Suggest potential solution

The behavior of podman kube play should be changed so that it starts pods in parallel.

Have you considered any alternatives?

Currently, the YAMLs fed to podman kube play - must be sorted in dependent order by hand, e.g. the pod for PostgreSQL must come before other pods which depend on it.

Additional context

I first brought up this issue last year in the June 2023 community meeting, see https://chrisproject.org/blog/2023/06/06/chris-at-podman-community-meeting

Currently I am trying to unify our production Helm YAMLs with the YAMLs we use for Podman, so that it it is possible to do

helm template chris fnndsc/chris -f values.yaml | podman kube play --replace -

Without this feature implemented, the above will not work.

In the meantime, I am considering writing a helper script to sort the YAMLs in dependency order, so that I can do

helm template chris fnndsc/chris -f values.yaml \
  | podman run --rm -i ghcr.io/fnndsc/hypothetical-yaml-sorter:latest \
  | podman kube play --replace -
rhatdan commented 1 week ago

Interested in opening a PR to fix?

jennydaman commented 1 week ago

I would, but I don’t know Go…

I can be convinced to take it up as a side-project (over the timespan of months)… @rhatdan do you have any comments about implication? E.g. is there a reason why the current behavior isn’t parallel, or why it might be particularly difficult? Does anyone or anything depend on the sequential behavior? From an outsider’s perspective it seems embarrassingly parallel.

Luap99 commented 1 week ago

Well the question is how is the behavior defined? Creating pods in parallel may not be difficult to implement but what should happen if one pod fails to be started/created. Do the other in parallel created pods needs to be stopped/removed again, etc...? I don't think the current serial code cares much about this and just exits so I guess it would not matter for parallel as well then but one thing that would change is that later pods are created even if the first one failed. I don't know enough about kube play to know whenever this would be a real problem or not.

jennydaman commented 1 week ago

what should happen if one pod fails to be started/created

I think mimicking the behavior of Kubernetes/kubectl would be the way to go: if one pod fails, everything else just keeps running and you have a failed pod.

rhatdan commented 1 week ago

@ygalblum Thoughts?

I think the current code is just reading through the kube.yaml, and processing it as it goes. Would need to setup a thread function for each pod and then allow them to run.

Not having to deal with one Pod failing should make this easier to handle.