kubectl 是 Kubernetes 的命令行工具(CLI),是 Kubernetes 用户和管理员必备的管理工具。该kubectl工具控制Kubernetes集群管理器。它可以让您检查集群资源,创建、删除和更新组件以及更多功能。kubectl 提供了大量的子命令,方便管理 Kubernetes 集群中的各种功能。
krew 是一个用来管理 kubectl 插件的工具,类似于 apt 或 yum,支持搜索、安装和管理kubectl 插件。
# yum -y install git
官方地址:https://krew.sigs.k8s.io/docs/user-guide/setup/install/
(
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
KREW="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
tar zxvf "${KREW}.tar.gz" &&
./"${KREW}" install krew
)
# export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
# 可以永久写的用户的环境变量文件,避免登出后失效。
# cat ~/.bashrc
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
# kubectl plugin list
The following compatible plugins are available:
/root/.krew/bin/kubectl-krew
# kubectl krew update
Updated the local copy of plugin index.
# kubectl krew search
# kubectl krew search crt
# kubectl krew install get-all
# kubectl krew install ns tail
# kubectl krew list
PLUGIN VERSION
get-all v1.2.1
krew v0.3.2
ns v0.7.1
tail v0.10.1
# kubectl krew info ns
NAME: ns
URI: https://github.com/ahmetb/kubectx/archive/v0.7.1.tar.gz
SHA256: 6df4def2caf5a9c291310124098ad6c4c3123936ddd4080b382b9f7930a233ec
VERSION: v0.7.1
HOMEPAGE: https://github.com/ahmetb/kubectx
DESCRIPTION:
Also known as "kubens", a utility to set your current namespace and switch
between them.
CAVEATS:
\
| If fzf is installed on your machine, you can interactively choose
| between the entries using the arrow keys, or by fuzzy searching
| as you type.
|
| See https://github.com/ahmetb/kubectx for customization and details.
/
更新插件ns,由于是最新版所以更新失败,可通过命令’kubectl krew upgrade’更新全部插件
# kubectl krew upgrade ns
Updated the local copy of plugin index.
F1118 17:21:47.271927 81116 root.go:58] failed to upgrade plugin "ns": can't upgrade, the newest version is already installed
# kubectl
kubectl kubectl-get_all kubectl-krew kubectl-ns kubectl-tail
# kubectl ns weave
# kubectl-ns default
装完插件后可通过命令kubectl
或者kubectl-
使用插件,比如’kubectl ns weave’和’kubectl-ns default’都可以切换默认表空间
该命令类似’kubectl get all --all-namespaces’,但更全。
# kubectl-get_all
tail为输出pod日志,以上命令分别为:输出全部pod日志、输出所有命名空间default的pod日志、输出全部命名空间中所有replicaset为kubeapps-8fd98f6f5的pod日志、输出命名空间为kubeapps且replicaset为kubeapps-8fd98f6f5的pod日志。
# kubectl-tail
# kubectl-tail --ns default
# kubectl-tail --rs kubeapps-8fd98f6f5
# kubectl-tail --rs kubeapps/kubeapps-8fd98f6f5
卸载插件tail
# kubectl krew uninstall tail
Uninstalled plugin tail
主要是删除用户目录下的.krew
隐藏文件夹:rm -rf ~/.krew
1.查看安装目录
# kubectl krew version
OPTION VALUE
GitTag v0.3.2
GitCommit bd754e1
IndexURI https://github.com/kubernetes-sigs/krew-index.git
BasePath /root/.krew
IndexPath /root/.krew/index
InstallPath /root/.krew/store
DownloadPath /tmp/krew-downloads
BinPath /root/.krew/bin
2.卸载
# rm -rf /root/.krew