Search code examples
sshopenshiftredash

Install python libraries on all openshift pods


I have a redash server deployed on an on premise openshift cluster, with about 20 pods. I want to install new python libraries on the server and I'm able to ssh to one of the pods using oc rsh and run pip install x.

The problem is that I have a lot of pods and don't want to ssh to each pods when I need a new library. I also don't want to change the image and have to redeploy my server every time. Is there a way to run a command on all pods at the same time?


Solution

  • It is generally not a good idea to do Pod maintenance using oc rsh. The right way to go here would be to update the container image and redeploy your application, that is how Kubernetes / OpenShift works.

    For example, when one of your Pods is restarted for any reason (the underlying Node has an issue, your application crashes, an administrator deletes a Pod, ...) then your change will be gone as the Pod is restarted.

    Usually, container images are built via a pipeline or similar, so re-building an image should not be an issue. That being said, a hacky way to run a command in all Pods is the following:

    for pod in $(oc get pods -o name); do
      oc rsh $pod pip install x
    done