I'm creating a bash script file for doing some operation as
1. Do some operations
2. Go inside kubernetes cluster (kubectl exec -it <pod> --bash)
3. Copying some files
4. Connecting to mongo
5. Adding some data to collections
6. Exit from mongo -----------> step 1
7. Exit from k8s cluster -------> step2
8. Do some operations
Problem : I'm getting problem in Exit command( step1 and step2). It is exiting from script file not from mongo or k8s cluster.
What I have tried
It worked if I'm passing all commands inside options "c" as below:
kubectl exec -it <pod> --bash -c "echo text && exit"
But If I'm using any function( which I created in script) with "c" options then it din't work.
test() { // some code }
kubectl exec -it <pod> --bash -c "test && exit" // couldn't find test
Also -c option is not working with mongo command.
Does anyone have any idea about it?