简体   繁体   中英

How to execute a shell script as input on an interactive bash pod in Kubernetes?

I have a shell script my-script.sh like:

#!/bin/bash
while true; do
  echo '1'
done

I can deploy a bash pod in Kubernetes like:

kubectl run my-shell --rm -it --image bash -- bash

Now, I want to execute the script on bash. How can I pass my-script.sh as input to bash? Something like

kubectl run my-shell --rm -it --image bash -- /bin/bash -c < my-script.sh

Just drop the -t to kubectl run (because you're reading from stdin, not a terminal) and the -c from bash (because you're passing the script on stdin, not as an argument):

$ kubectl run my-shell --rm -i --image docker.io/bash -- bash < my-script.sh
If you don't see a command prompt, try pressing enter.
1
1
1
1
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM