Injecting a script to Pod with docker returns EOF

4/18/2018

my goal is to execute a script once on a permanently running pod in kubernetes. The pod is called busybox-<SOME_ID> and finds itself in the namespace default.Therefore, I wrote this script - called scan-one-pod.sh:

#!/bin/bash
export MASTER_IP=192.168.56.102
export SCRIPT_NAME=script.sh
export POD_NAMESPACE=default
export POD_NAME=busybox

echo "echo HALLO" | ssh ubuntu@$MASTER_IP
export POD_ID=$(kubectl get po | grep busybox | sed -n '1p'|awk '{print $1}')
kubectl cp $SCRIPT_NAME $POD_NAMESPACE/$POD_ID:.
kubectl exec  $POD_ID -- chmod +x $SCRIPT_NAME
export CONTAINER_ID=$(kubectl describe pod busybox | grep 'Container ID' | sed -n '1p'|awk '{print $3}')
ssh -t ubuntu@$MASTER_IP "sudo docker exec -u root $CONTAINER_ID -- ./script.sh"

The referred script script.sh has the following content:

$ kubectl exec  $POD_ID --  cat script.sh
#!/bin/bash
echo "test" >> test
cp test test-is-working

However, it is not possible to run the script on the pod:

  • the files test and test-is-working are not created
  • the script scan-one-pod.sh returns just EOF:

    $ ./scan-one-pod.sh
    Pseudo-terminal will not be allocated because stdin is not a terminal.
    Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    
    155 Software-Pakete können aktualisiert werden.
    72 Aktualisierungen sind Sicherheitsaktualisierungen.
    
    
    HALLO
    [sudo] Passwort für ubuntu:
    EOF
    Connection to 192.168.56.102 closed.
  • If I execute the docker-command directly, remote on my kubernetes-controller, I get the same message of EOF:

    ubuntu@controller:~$ export CONTAINER_ID=$(kubectl describe pod busybox | grep 'Container ID' | sed -n '1p'|awk '{print $3}')
    ubuntu@controller:~$ sudo docker exec -u root $CONTAINER_ID  ./script.sh
    EOF
    
  • If I execute it from my local workstation via kubectl exec I get this error:

    $ kubectl exec  $POD_ID  ./script.sh
    rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"no such file or directory\"\n"

    I don't know, which missing file they are referring to, but the script.sh-file is present and the busybox-pod seems to be running:

    $ kubectl exec  $POD_ID  ls script.sh
    script.sh
    
    $ kubectl get po busybox-6bdf9b5bbc-4skds
    NAME                       READY     STATUS    RESTARTS   AGE
    busybox-6bdf9b5bbc-4skds   1/1       Running   10         12d

Question: As far as I know, EOF means End-Of-File. End of which file would be important for me to know, and why is that a problem?

Thanks in advance, any help is appreciated :)

-- Verena I.
bash
docker
eof
kubernetes

0 Answers