Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...