Reputation: 89
I am trying to write a python script using one of the sdk by my org, and extract some useful information from kubernetes pod.
The sdk I have has a podexec() function which can be used to execute a command inside the pod.
I have a specific usecase, where I've to execute a command inside of the pod, which inturn will spin up an interactive shell, and then in that interactive shell, I want to execute a command and print the output.
For example, Let's say there's a mysql pod, and I want to first exec into the mysql pod, and then run mysql command which will bring up an interactive mysql shell, where I want to enter some commands like "Show tables;", and then get the output of that command in my script. Is it possible?
After getting into the pod, I am able to run a single command like below
kubectl exec -it mysql-pod -- bash
echo "show tables;" |mysql
Now how to run this without entering the pod with just the kubectl?
NOTE: My usecase is not w.r.t mysql actually. My org has a custom tool which lets us execute commands in it's interactive shell. Mysql here is just an example.
Upvotes: 1
Views: 1325
Reputation: 89
Ok. Figured it out.
kubectl exec -it mysql-pod -- bash -c "echo \"show tables\" |mysql"
Upvotes: 1