Using fzf and oc to rsh into an OpenShift Pod
Getting a remote shell on an OpenShift pod is simple enough; you type:
$ oc rsh <pod name>
Pod names can be long and complex, however. Here’s an example:
mysql-coolapp-5-rg59c
Only a luddite would willingly type all of that, and mousing around a terminal to copy and paste is only slightly more efficient. If you have fzf installed, however, you can use fuzzy finding to type only a few characters of the pod name to rsh into it. Here’s a zsh function that seems to work fine in bash as well. Add it to your dotfiles somewhere, and then you can just type “ocsh” and then a few characters of the pod name (or use the arrow keys) and then press Enter, and voila.
EDIT (8/12/2019) — A colleague just informed me that you can rsh into the deployment configuration name, e.g.:
$ oc rsh dc/myapp
I had no idea, and it’s definitely easier than typing the pod name. Thanks, Gary!