乐趣区

Kubernetes插件管理工具krew安装和使用

一. 安装

参考官方文档. MacOS 和 Linux 上可通过如下命令安装:

(set -x; cd "$(mktemp -d)" &&
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.{tar.gz,yaml}" &&
  tar zxvf krew.tar.gz &&
  KREW=./krew-"$(uname | tr'[:upper:]''[:lower:]')_amd64"&&"$KREW"install --manifest=krew.yaml --archive=krew.tar.gz &&"$KREW" update
)

安装完成后, 将 $HOME/.krew/bin 添加到 PATH 环境变量中, 可以通过在 .bashrc.zshrc文件中添加如下脚本实现:

export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

验证安装成功:

$ kubectl krew

二. 使用

参考: 官方文档 QuickStart.

2.1 krew update – 更新本地数据库

类似于 ’apt update’.

$ kubectl krew update
Updated the local copy of plugin index.

2.2 krew search – 搜索插件

# 列出全部可用插件
$ kubectl krew search
...
# 搜索指定插件
$ kubectl krew search access-matrix
NAME           DESCRIPTION                                      INSTALLED
access-matrix  Show an RBAC access matrix for server resources  no

2.3 krew install – 安装插件

$ kubectl krew install access-matrix
Updated the local copy of plugin index.
Installing plugin: access-matrix
...

2.4 krew XXX – 使用插件

# 使用 access-matrix 插件
$ kubectl access-matrix

2.5 krew upgrade – 升级全部插件

$ kubectl krew upgrade

2.6 krew uninstall – 卸载插件

$ kubectl krew uninstall access-matrix
...

三. 插件列表

全部插件列表官方地址.

四. 附录

4.1 安装日志

$ (set -x; cd "$(mktemp -d)" &&
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.{tar.gz,yaml}" &&
  tar zxvf krew.tar.gz &&
  KREW=./krew-"$(uname | tr'[:upper:]''[:lower:]')_amd64"&&"$KREW"install --manifest=krew.yaml --archive=krew.tar.gz &&"$KREW" update
)
++ mktemp -d
+ cd /tmp/tmp.XNWntATcr5
+ curl -fsSLO 'https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.{tar.gz,yaml}'
+ tar zxvf krew.tar.gz
./LICENSE
./krew-darwin_amd64
./krew-linux_amd64
./krew-linux_arm
./krew-windows_amd64.exe
++ uname
++ tr '[:upper:]' '[:lower:]'
+ KREW=./krew-linux_amd64
+ ./krew-linux_amd64 install --manifest=krew.yaml --archive=krew.tar.gz
Installing plugin: krew
Installed plugin: krew
\
 | Use this plugin:
 |     kubectl krew
 | Documentation:
 |     https://sigs.k8s.io/krew
 | 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://sigs.k8s.io/krew.
 | /
/
+ ./krew-linux_amd64 update
WARNING: To be able to run kubectl plugins, you need to add
the following to your ~/.bash_profile or ~/.bashrc:

    export PATH="${PATH}:${HOME}/.krew/bin"

and restart your shell.

Updated the local copy of plugin index.
退出移动版