Editing Files In a Pods In Kubernetes

7/19/2017

I am trying to edit a file in my pod from my local machine using kubectl exec, but it is not working!

Example: Suppose I am working on Ubuntu and having a pod named "Pod1", I want to edit a file named /lists inside Pod1. I am doing this kubectl exec Pod1 cat /lists >> "HELLO" but it is not working, please how to solve this kind of problem!

-- Hassan Shaitou
containers
kubernetes
ubuntu

1 Answer

7/19/2017

You can't cat a local file over. One way is to store the file in a BASH variable first before sending it over

lists=$(cat /lists); kubectl exec Pod1 "echo $lists >> HELLO"

But this isn't a great way either. Are you attempting to debug the app or to automate some process by writing to a file this way? If it's the latter, may I suggest using a ConfigMap instead?

-- Eugene Chow
Source: StackOverflow