USR
USR

Reputation: 15

Passing sequence of commands to a running container

I have a executed command1 | command2 which runs from inside a container.

I am trying to run the same command by passing it to the running container, but it doesn't work. I tried kubectl -n namespace exec -it pod -- 'command1 | command2'

Any ideas? If pipes are not supported, any alternatives to run these 2 commands in sequence ?

Upvotes: 0

Views: 47

Answers (1)

larsks
larsks

Reputation: 311288

The arguments to the kubectl exec command are executed directly, without a shell. Because you're passing not a single command but a shell expression, this isn't going to work.

The solution is to explicitly invoke the shell:

kubectl -n namespace exec -it pod -- sh -c 'command1 | command2'

For example:

$ kubectl exec -it fedora0 -- sh -c 'echo hello world | sed s/hello/goodbye/'
goodbye world

Upvotes: 1

Related Questions