官方文档:https://krew.sigs.k8s.io/docs/user-guide/quickstart

下载 krew 安装包

GitHub: https://github.com/kubernetes-sigs/krew image.png

解压 krew.tar.gz

  1. tar zxvf krew.tar.gz

安装 krew

./krew install krew

报错,需要安装 Git

[root@master krew]# ./krew-linux_amd64 install krew
Adding "default" plugin index from https://github.com/kubernetes-sigs/krew-index.git.
F1015 13:32:07.428945    9477 root.go:79] failed to add default plugin index in absence of no indexes: command execution failure, output="": exec: "git": executable file not found in $PATH

安装 Git,再次执行 ./krew install krew 即可。

安装成功提示信息

[root@master krew]# ./krew-linux_amd64 install krew
Adding "default" plugin index from https://github.com/kubernetes-sigs/krew-index.git.
Updated the local copy of plugin index.
Installing plugin: krew
Installed plugin: krew
\
 | Use this plugin:
 |     kubectl krew
 | Documentation:
 |     https://krew.sigs.k8s.io/
 | Caveats:
 | \
 |  | krew is now installed! To start using kubectl plugins, you need to add
 |  | krew's installation directory to your PATH:
 |  |
 |  |   * macOS/Linux:
 |  |     - Add the following to your ~/.bashrc or ~/.zshrc:
 |  |         export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
 |  |     - Restart your shell.
 |  |
 |  |   * Windows: Add %USERPROFILE%\.krew\bin to your PATH environment variable
 |  |
 |  | To list krew commands and to get help, run:
 |  |   $ kubectl krew
 |  | For a full list of available plugins, run:
 |  |   $ kubectl krew search
 |  |
 |  | You can find documentation at
 |  |   https://krew.sigs.k8s.io/docs/user-guide/quickstart/.
 | /
/

配置 krew 环境变量

vim ~/.bash_profile
export PATH="${PATH}:${HOME}/.krew/bin"
source ~/.bash_profile

测试是否安装成功

[root@master krew]# kubectl krew search
NAME                            DESCRIPTION                                         INSTALLED
access-matrix                   Show an RBAC access matrix for server resources     no
advise-psp                      Suggests PodSecurityPolicies for cluster.           no
allctx                          Run commands on contexts in your kubeconfig         no
apparmor-manager                Manage AppArmor profiles for cluster.               no
assert                          Assert Kubernetes resources                         no
...