Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubectl exec command to write contents to a file in the pod

I am trying below command

kubectl exec -it sss-pod-four  echo "hi" >> /mnt/sss/testnew.txt

But it throws error

-bash: /mnt/sss/testnew.txt: No such file or directory

What is the best way to achieve this

like image 376
ambikanair Avatar asked Mar 09 '18 08:03

ambikanair


People also ask

How do I edit a file in Kubernetes pod?

There are two ways to edit a file in an existing pod: either by using kubectl exec and console commands to edit the file in place, or kubectl cp to copy an already edited file into the pod.


1 Answers

Found a similar question here and below command works now

 kubectl exec -it sss-pod-four  -- bash -c "echo hi > /mnt/sss/testnew.txt" 
like image 166
ambikanair Avatar answered Sep 17 '22 16:09

ambikanair