Gave CKAD last year. I remember I had to use sudo tee filename instead of >&g . . .

Ramit Sharma:
Gave CKAD last year. I remember I had to use sudo tee filename instead of >> concat operation to write contents to a file. My question is, suppose am creating a pod whose command is supposed to write to a file. Should that command also use sudo tee instead of >> ?

unnivkn:
Hi Ramit… below is the command to write to a file which is already exists & write protedted.
k logs my-pod >> sudo tee /mypath/myfile.txt
cat /mypath/myfile.txt

Now if you need to write the defintion of a pod, you have to use:
k get po my-pod -n my-namespace -o yaml > my-pod.yaml
By deafult this will work & no need to use sudo for this.

Fernando Jimenez:
Hi @unnivkn I am afraid this

k logs my-pod >> sudo tee /mypath/myfile.txt

will not produce the result you expect. Perhaps

k logs my-pod | sudo tee -a /mypath/myfile.txt

unnivkn:
Thanks @Fernando Jimenez. You are right. I didn’t tested it. With out -a option also it works. k logs nginx | sudo tee f1.txt

Fernando Jimenez:
The -a is to append to the file f1.txt in case you do not want to override its content.

Karim Meslem:
I think @Ramit Sharma’s question is about creating a pod whose command is supposed to write to a file. Write text to file IN a container.
In that case, your command should look something like this:
bash -c "echo 'something' >> /app.txt"
I don’t think you need sudo and that you can use shell redirection instead of tee.