My goal is to write a simple init pod to echo something into a file using a redirect (>
) for testing purposes but instead, printing the redirect and file name. Here's the relevant part of my yaml:
initContainers:
- name: cat-to-file
image: alpine
args: [ "echo", "Hello, World", ">", "test"]
workingDir: /project
volumeMounts:
- name: project-files
mountPath: /project
But, the file doesn't get created and when I view the container logs via:
kubectl logs <pod id> cat-to-file
It shows me:
Hello, World, > test
Which makes me think it's echoing the > test
to stdout rather than to a file named test
.
What am I doing wrong here?
try this:
...
args: [ "/bin/sh", "-c", "echo Hello World > test"]
...
This approach worked for me here.