>_ZSH-OPENSHIFT-ALIASES
Drive your OpenShift cluster from zsh with two-to-six-character aliases. og pods instead of oc get pods, odep foo.yaml instead of oc apply -f foo.yaml, ocdev / ocqa for one-keystroke env-driven login, ologin for oc rsh into a pod. Tab-completion for oc is auto-sourced when the binary is on PATH; the whole plugin no-ops when oc is missing, so it is safe to load unconditionally.
Install
# Zinit
zinit ice lucid nocompile
zinit load MenkeTechnologies/zsh-openshift-aliases
# Oh My Zsh
git clone https://github.com/MenkeTechnologies/zsh-openshift-aliases \
"$HOME/.oh-my-zsh/custom/plugins/zsh-openshift-aliases"
# then add zsh-openshift-aliases to plugins=(...) in ~/.zshrc
# Manual
git clone https://github.com/MenkeTechnologies/zsh-openshift-aliases
source zsh-openshift-aliases/zsh-openshift-aliases.plugin.zsh
The plugin guards on type -ap -- oc — if no oc executable is on PATH it returns immediately and registers nothing. When oc is present and the __start_oc completion function is not already defined, it runs source <(oc completion zsh) to wire up oc tab-completion.
Configuration
Three environment variables drive the login macros. The plugin initializes all three to the empty string when it sources, so set them after the plugin loads — a value exported before sourcing is overwritten on load.
OCP_USERNAME | username passed to oc login -u by both ocdev and ocqa |
OCP_DEV_URL | cluster API URL ocdev logs into (e.g. https://api.dev.example.com:6443) |
OCP_QA_URL | cluster API URL ocqa logs into |
# in ~/.zshrc, AFTER the plugin is sourced
export OCP_USERNAME='your-username'
export OCP_DEV_URL='https://api.dev.example.com:6443'
export OCP_QA_URL='https://api.qa.example.com:6443'
Login & session
ocdev | oc login ${OCP_DEV_URL} -u ${OCP_USERNAME} — log into the dev cluster |
ocqa | oc login ${OCP_QA_URL} -u ${OCP_USERNAME} — log into the QA cluster |
ologin POD | oc rsh — open an interactive remote shell into a running pod |
Get resources
Short reads over oc get. The -o wide variants add the extra columns (node, IP) oc hides by default.
og ARGS | oc get — the base getter |
odc | oc get dc -o wide — deployment configs |
osts | oc get sts -o wide — statefulsets |
ohpa | oc get hpa — horizontal pod autoscalers |
opod | oc get pod -o wide |
osvc | oc get svc -o wide |
opvc | oc get pvc -o wide |
ois | oc get is -o wide — image streams |
obc | oc get bc -o wide — build configs |
oall | oc get all -l run= — everything for a given run label |
oalln APP | oc get all -l run=APP -o name — names only |
opodo APP | oc get pod -l app=APP -o wide — pods for an app label |
opd APP | oc get pod -l app=APP -o jsonpath='{ .metadata.name }' |
oimg | oc get pods -o jsonpath='{..image}' piped through tr/sort/uniq -c — image usage tally |
olcp | oc get pods jsonpath dump of pod name → container images, sorted |
olp APP | oc get pods -o jsonpath='{..image}' -l app=APP — images for an app label |
Describe, deploy, logs, copy
odesc ARGS | oc describe |
odhist | oc rollout history dc |
odep FILE | oc apply -f FILE — apply a manifest |
oroll DC | oc rollout latest dc/DC — trigger a new rollout |
orhist DC | oc rollout history dc/DC |
olog ARGS | oc logs -f — follow logs |
osync ARGS | oc rsync |
ocp ARGS | oc cp — copy files in/out of a pod |
ovol | oc volume dc --all |
Delete resources
odel ARGS | oc delete — the base deleter |
odelo KIND APP | oc delete KIND -l app=APP |
odela APP | oc delete all -l app=APP |
odeldc | oc delete dc |
odelsts | oc delete sts |
odelpod | oc delete pod |
odelsvc | oc delete svc |
odelbc | oc delete bc |
odelpvc | oc delete pvc |
Export YAML config
Each dumps a resource as YAML with --export for re-applying elsewhere.
oexp ARGS | oc get ARGS -o yaml --export |
opexp POD | oc get pod POD -o yaml --export |
odexp DC | oc get dc DC -o yaml --export |
osexp STS | oc get sts STS -o yaml --export |
ocexp CM | oc get cm CM -o yaml --export — config map |
ovexp PVC | oc get pvc PVC -o yaml --export |
Scaling
oscaled N DC | oc scale --replicas=N dc DC |
oscales N STS | oc scale --replicas=N statefulsets STS |
ostopd DC | oc scale --replicas=0 dc — scale a dc to zero |
ostartd DC | oc scale --replicas=1 dc |
ostarts STS | oc scale --replicas=1 statefulsets |
ostops STS | oc scale --replicas=0 statefulsets |
Five shell functions step replica counts by one, reading the current count via oc get ... -o jsonpath='{.spec.replicas}' then re-scaling:
oincd DC / oincs STS | increment a deployment config / statefulset replica count by 1 |
odecd DC / odecs STS | decrement a deployment config / statefulset replica count by 1 |
pod SELECTOR | print the name of the running pod matching a label selector via jsonpath |
Pod hygiene & backup
opclean | force-delete every pod stuck in Terminating (--grace-period=0 --force) |
opodr | jsonpath list of pod names in phase Running |
opodt | jsonpath list of pod names in phase Terminating |
obackup | dump all + per-object-type YAML (rolebindings, serviceaccounts, secrets, cm, pvc, statefulsets, hpa, deployments, …) into the current directory for project backup |
Workflow
# log into the dev cluster (set OCP_* first)
ocdev
# list pods with node + IP columns
opod
# tail logs of a deployment, follow
olog deployment/web
# apply a manifest
odep web.yaml
# scale a deployment config to 3, or step it up by 1
oscaled 3 web
oincd web
# remote shell into a pod
ologin web-7d9f8c-abcde
# force-clear stuck Terminating pods
opclean
Engineering report
For the full breakdown — the exact oc command each alias expands to, the load guard, the oc completion zsh sourcing, the helper-function internals, and the zunit test map — see the engineering report.