Search code examples
kubernetesgoogle-kubernetes-enginekubernetes-podkubernetes-container

Is it possible to add a new Container once Pod is created?


Suppose I have created a Pod having 1 container, now I want to add a second container to it, how can I do that?


Solution

  • In general, the answer is "no". Once you have created a Pod, you cannot add a new Container to it. Read the official note:

    Since Pods are intended to be disposable and replaceable, you cannot add a container to a Pod once it has been created.

    However, sometimes it's necessary to inspect the state of an existing Pod, for example, to troubleshoot a hard-to-reproduce bug. In these cases, you can run an Ephemeral Container in an existing Pod to inspect its state and run arbitrary commands.

    But before you think that you can create an ephemeral container to run your application and add to a running Pod, please note that Ephemeral Containers are not appropriate for running applications because they lack guarantees for resources or execution, and they will never be automatically restarted