工具
kubectx
what?
切换context、namespace
$ kubectx minikube
Switched to context "minikube".
$ kubens kube-system
Context "test" set.
Active namespace is "kube-system".
fzf
what?
fzf:fuzzy finder,一个通用的命令行模糊搜索工具
主要用来列举env、context、namespace并交互式选择
扩展shell
what?
切换环境test or prod
1.新增kubecfg到~/.kube/fzf目录
~/.kube/fzf/test
~/.kube/fzf/prod
2.添加以下函数到实际启动shel中,如/.zshrc、/.bashrc
alias k='kubectl'
kubecfg(){
current_context=$(ls ~/.kube/fzf |fzf) export KUBECONFIG=~/.kube/fzf/$current_context
echo "Switched to cfg $KUBECONFIG."
}
使用
1.选择环境
kubecfg
2.选择context
kubectx
3.选择namespace
kubens
4.kubectl
k get po
标签:what,k8s,命令行,namespace,扩展,kubectx,context,kube,fzf
From: https://www.cnblogs.com/xiaohan970121/p/18330925