Easy to switch namespace of kubectl. And avoid the trouble of typing namespace every time.
tag=$(curl https://api.github.com/repos/zhranklin/easy_kubectl/releases/latest -s|grep tag_name|sed 's/.*tag_name": "//g; s/",.*//g')
source <(curl -fsSL https://github.com/zhranklin/easy_kubectl/archive/$tag.tar.gz | tar xzO easy_kubectl-$tag/install.sh)
To enable the kubectl auto-completion(official), you may install bash-completion, such like:
yum install -y bash-completion
Installation of bash-completion needs relogin.
export FZF_TARGET=<target platform> # e.g. linux_amd64
tag=$(wget -qO - https://api.github.com/repos/zhranklin/easy_kubectl/releases/latest|grep tag_name|sed 's/.*tag_name": "//g; s/",.*//g')
wget -qO - https://github.com/zhranklin/easy_kubectl/archive/$tag.tar.gz | tar xzO easy_kubectl-$tag/install.sh > install.sh
GEN_OFFLINE=1 source install.sh > install-offline.sh
You will get file install-offline.sh
, execute at target environment:
source install-offline.sh
Just run update_k
There are two ways:
k+Enter
, then search namespace, it supports fuzzy search(Powered by fzf).k <keyword>
, if only one result matched, the result will be selected.
Replace kubectl with k and execute kubectl command without specifying namespace.
If --context
flag should be set, run k c <context>
Interpolated command hint is printed through stderr, not stdout:
k get pod -l istio=pilot -o jsonpath='{.items[0].metadata.name}'
---
kubectl -n istio-system get pod -l istio=pilot -o jsonpath={.items[0].metadata.name}
istio-pilot-5fb44ddbc-2wkkx
It's printed to stderr, so the grammar like $(xxx) xxx
will be still fine:
$ k get po $(k get pod -l istio=pilot -o jsonpath='{.items[0].metadata.name}')
---
kubectl -n istio-system get pod -l istio=pilot -o jsonpath={.items[0].metadata.name}
kubectl -n istio-system get po istio-pilot-7c949bbc49-2qd4n
NAME READY STATUS RESTARTS AGE
istio-pilot-7c949bbc49-2qd4n 2/2 Running 0 3h
First 2 lines are the hints and the last 2 lines are the output of kubectl.