redirecting exec output to a file in container

4,810 views
Skip to first unread message

vavili...@gmail.com

unread,
Feb 1, 2017, 12:22:43 PM2/1/17
to Kubernetes user discussion and Q&A
Hi,

I'm trying to start a process using exec and redirect the stdout and stderr to a file in the container. I have a single container in a pod. I've tried the following combinations, but none see to work as expected. Is there any other way to achieve this behavior?

kubectl -n kube-system exec -it <pod-name> -- nohup sh -c '<process-command-with-args> &' > <log-file>
------->> -bash: <log-file>: Permission denied // It's trying to redirect the output to the host file

kubectl -n kube-system exec -it <pod-name> -- nohup sh -c '<process-command-with-args> > <log-file> &'
This command starts the process in the background but redirects the logs to nohup.out file instead of the log-file specified.

In general is there a way to execute multiple command line features like redirection and pipes in the container?

Thanks,
Divya

Rodrigo Campos

unread,
Feb 3, 2017, 10:43:28 AM2/3/17
to kubernet...@googlegroups.com
You probably need your bash (in your host) to not interpret the redirection. You need to escape it for that.

As a quick and maybe dirty solution, you can also create the script in the container with the redirection inside it (i.e the command in the script file already does the redirection).
--
You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-use...@googlegroups.com.
To post to this group, send email to kubernet...@googlegroups.com.
Visit this group at https://groups.google.com/group/kubernetes-users.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

vavili...@gmail.com

unread,
Feb 3, 2017, 1:21:06 PM2/3/17
to Kubernetes user discussion and Q&A
Yes, I was working around this with a script inside the container and yes it's a dirty solution for now. Looking for better solutions.
Could you explain what you mean by escaping it for host skipping redirection?

Rodrigo Campos

unread,
Feb 3, 2017, 9:55:42 PM2/3/17
to kubernet...@googlegroups.com
Cool that works.

Escape as in shell, using it inside single quotes or backslash (shells are a PITA with this stuff) or that stuff. Sorry for the shitty answer, but I'm on my phone and on holidays, far away from a PC, so can't try the command and send something that works.

If you are using bash, including the > inside the single quotes *might* do the trick


On Friday, February 3, 2017, <vavili...@gmail.com> wrote:
Yes, I was working around this with a script inside the container and yes it's a dirty solution for now. Looking for better solutions.
Could you explain what you mean by escaping it for host skipping redirection?

Reply all
Reply to author
Forward
0 new messages