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

Time:06-22

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

CodePudding user response:

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
...
  • Related