0

I am trying to create and delete file from the same pod and get error that the file not found, any idea?

one container creates the file and the second should delete it...

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  volumes:
    - name: shared
      emptyDir: { }
  containers:
    - name: createfile
      image: debian
      command: [ "/bin/sh", "-c" ]
      args:
        - while true; do
          touch /usr/test.txt;
          ls
          echo "new file created on container";
          sleep 30;
          done
      volumeMounts:
        - name: shared
          mountPath: /usr/
    - name: deletefile
      image: debian
      volumeMounts:
        - name: shared
          mountPath: /usr/
      command: [ "/bin/sh", "-c" ]
      args:
        - while true; do
          rm /usr/test.txt;
          ls
          echo "container 2 - file removed";
          sleep 30;
          done

The error which I got is: ls: error while loading shared libraries: libpcre2-8.so.0: cannot open shared object file: No such file or directory

Is it because I am running ls in the container, any idea why? As I use Debian, not sure what is the issue

knittl
  • 246,190
  • 53
  • 318
  • 364
JME
  • 881
  • 2
  • 11
  • 23
  • 1
    The error message means that your container doesn't have/find the libraries required by `ls` – Fravadona May 08 '22 at 15:05
  • Change your scripts and mountPath. Leave /usr alone. Use /tmp or some unused directory. Mounting an emptyDir on /usr, your /usr/lib and /usr/bin are gone. – SYN May 08 '22 at 15:41

1 Answers1

1

Yes, the error was linked to the debian image (there is few solutions here:Error while loading shared libraries: 'libpcre.so.0: cannot open shared object file: No such file or directory' ) AND to your while script.

but howerver, I was able to fix this by using bash image and modify a little bit your script see the manifest:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  volumes:
    - name: shared
      emptyDir: { }
  containers:
    - name: createfile
      image: bash
      command: [ "/bin/sh", "-c" ]
      args:
        - while true; do
          touch /usr/test.txt && ls /usr/ && echo "new file created on container" && sleep 10;
          done
      volumeMounts:
        - name: shared
          mountPath: /usr/
    - name: deletefile
      image: bash
      volumeMounts:
        - name: shared
          mountPath: /usr/
      command: [ "/bin/sh", "-c" ]
      args:
        - while true; do
          rm /usr/test.txt && ls /usr/ && echo "container 2 - file removed" && sleep 10;
          done

createfile output:

❯ k logs -f mypod -c createfile
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
new file created on container
test.txt
...

deletefile output:

❯ k logs -f mypod -c deletefile
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
container 2 - file removed
...
Bguess
  • 1,700
  • 1
  • 11
  • 24