Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a 'command with arguments' on a container of 'multi-container pod'?

I have an app/pod: app1 with 2 containers service1 and service2. These services writes log at /var/log/app1Service1.log and /var/log/aapp1Service2.log. I'd like to tail log from mac's cli. Tried as below but did not work.

~ $ kubectl exec app1-6f6749ccdd-4ktwf -c app1Service1 "tail -f -n +1 /var/log/app1Service1.log"
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"tail -f -n +1 /var/log/app1Service1.log\": stat tail -f -n +1 /var/log/app1Service1.log: no such file or directory"

command terminated with exit code 126
~ $

below command works:

kubectl exec app1-6f6749ccdd-4ktwf -c app1Service1 ls
kubectl exec app1-6f6749ccdd-4ktwf -c app1Service1 "ls"

Seeing failures when I pass arguments to command.

like image 410
Robert Ranjan Avatar asked Dec 04 '18 02:12

Robert Ranjan


People also ask

How do you pass arguments to containers in Kubernetes?

To define arguments for the command, include the args field in the configuration file. The command and arguments that you define cannot be changed after the Pod is created. The command and arguments that you define in the configuration file override the default command and arguments provided by the container image.

How do you communicate between two containers in a pod?

Containers in a Pod share the same IPC namespace, which means they can also communicate with each other using standard inter-process communications such as SystemV semaphores or POSIX shared memory.

Can you run multiple containers in a pod?

Pods that run multiple containers that need to work together. A Pod can encapsulate an application composed of multiple co-located containers that are tightly coupled and need to share resources.


1 Answers

Add bash -c or if your container has sh then add sh -c

kubectl exec app1-6f6749ccdd-4ktwf -c app1Service1 -- bash -c "tail -f -n +1 /var/log/app1Service1.log"

Hope this'll help

like image 52
Abu Hanifa Avatar answered Nov 14 '22 23:11

Abu Hanifa