Kubernetes Redirecting echo into a file not creating file

10/8/2018

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?

-- Aaron N. Brock
kubernetes

1 Answer

10/8/2018

try this:

...
args: [ "/bin/sh", "-c", "echo Hello World > test"]
...

This approach worked for me here.

-- Jiri Kremser
Source: StackOverflow