Monday, September 14, 2015

Copy files to running OpenShift 3 pods

Needed to copy a newer mysql client for debugging purposes into an OpenShift v3 pod. /fortunately the mysql client binary is self contained and does not need special shared libs; worked with v5.6.26/

Here's how I managed to do so:

oc exec -i [pod name]  -n [project] -- bash -c 'cat > [remote file]' < [local file]

e.g.
oc exec -i mysql-55-centos7-1-f42js  -n 0wwwv -- bash -c 'cat > /tmp/mysql' < /tmp/mysql

What does it do?

Invokes `exec` command with `-i` option so that stdin is passed (otherwise stdin is ignored). The remote command cats everything into desired path. You need to `chmod 755 [file]` inside the pod if that file is to be executed.

To get into the pod in a shell try `oc rsh`.