Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing multiple commands( or from a shell script) in a kubernetes pod

I'm writing a shell script which needs to login into the pod and execute a series of commands in a kubernetes pod.

Below is my sample_script.sh:

kubectl exec octavia-api-worker-pod-test -c octavia-api bash unset http_proxy https_proxy mv /usr/local/etc/octavia/octavia.conf /usr/local/etc/octavia/octavia.conf-orig /usr/local/bin/octavia-db-manage --config-file /usr/local/etc/octavia/octavia.conf upgrade head 

After running this script, I'm not getting any output. Any help will be greatly appreciated

like image 748
ahmed meraj Avatar asked Apr 19 '17 14:04

ahmed meraj


People also ask

How do you pass multiple commands in Kubernetes Yaml?

The first part(command: ["/bin/sh","-c"]) just tells the machine to run a shell and then run the following commands. The portion in args is where the actual commands are passed to the shell. You use semicolon to separate the commands. OR an easier wary in my opinion is to build your own dockerfile.

Can a Kubernetes pod have multiple services?

As many Services need to expose more than one port, Kubernetes supports multiple port definitions on a Service object. Each port definition can have the same protocol , or a different one.

How do you use POD commands?

When you create a Pod, you can define a command and arguments for the containers that run in the Pod. To define a command, include the command field in the configuration file. To define arguments for the command, include the args field in the configuration file.


Video Answer


1 Answers

Are you running all these commands as a single line command? First of all, there's no ; or && between those commands. So if you paste it as a multi-line script to your terminal, likely it will get executed locally.

Second, to tell bash to execute something, you need: bash -c "command".

Try running this:

$ kubectl exec POD_NAME -- bash -c "date && echo 1"  Wed Apr 19 19:29:25 UTC 2017 1 

You can make it multiline like this:

$ kubectl exec POD_NAME -- bash -c "date && \       echo 1 && \       echo 2" 
like image 146
ahmet alp balkan Avatar answered Sep 27 '22 21:09

ahmet alp balkan