Skip to content

zhranklin/easy_kubectl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easy_kubectl

Easy to switch namespace of kubectl. And avoid the trouble of typing namespace every time.

Install

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.

Generate offline installer

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

Update

Just run update_k

Usage

Select namespace

There are two ways:

  1. k+Enter, then search namespace, it supports fuzzy search(Powered by fzf).
  2. k <keyword>, if only one result matched, the result will be selected.

Execute command

Replace kubectl with k and execute kubectl command without specifying namespace.

Autocompletion

Select context

If --context flag should be set, run k c <context>

Command hint

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.

About

Kubectl command namespace switcher

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages