Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

ssh - 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?

question from:https://stackoverflow.com/questions/66052009/install-python-libraries-on-all-openshift-pods

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...