<p>I have two containers on same k8 pod, <code>container1, container2</code></p>

<p>I have python script in <code>container1</code>, How can I run this python script on <code>container2</code> ?</p>

<p>I mean something like ssh:</p>

<pre><code>ssh user@container2 python &lt; script_on_container1.py 
</code></pre>

ArmoArmo
<p>You can't; you need to make a network request from one container to the other.</p>

<p>I would suggest prototyping this first in a local Python virtual environment.  In <code>container2</code>, run some lightweight HTTP server like Flask, and when it receives a request, it calls whatever code the script would have run.  Once you've demonstrated this working, you can set up the same thing in local Docker containers, and if that works, make these two processes into two separate Kubernetes deployments.</p>

<p>In general with containers you can't "run commands" in other containers.  In your proposed solution, containers don't typically run ssh daemons, and maintaining valid login credentials without compromising them is really hard.  (If you put an ssh private key into a Docker image, anyone who has the image can trivially extract it.  Kubernetes secrets make this a little bit better but not great.)  The standard pattern for one container to invoke another is through a network path, generally either a direct HTTP request or through a queueing system like RabbitMQ.</p>
