安装方式二选一
脚本安装
Krew自身也表现为kubectl的一个插件,需要以手动方式独立安装。下面的脚本(krew-install.sh)能自动完成Krew插件的安装,该脚本仅适用于类UNIX系统平台,并以bash解释器运行
#!/bin/bash
set -x; cd "$(mktemp -d)"
curl -fSLO "https://github.com/kubernetessigs/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
手动安装
不过这个脚本我跑是没有成功过的,所以我直接上github下载了压缩包
Linux下载如下文件即可(链接)
然后通过上述链接进入之后下载如下yaml文件
[root@master ~]# set -x; cd "$(mktemp -d)" #可不执行
[root@master tmp.z0BIaOvPYU]# wget https://ghproxy.com/https://github.com/kubernetes-sigs/krew/releases/download/v0.4.1/krew.tar.gz #下载压缩包
[root@master tmp.z0BIaOvPYU]# wget https://ghproxy.com/https://github.com/kubernetes-sigs/krew/releases/download/v0.4.1/krew.yaml #下载yaml文件
执行以下命令
tar -xf krew-linux_amd64.tar.gz
./krew-linux_amd64 install --manifest=krew.yaml --archive=krew.tar.gz
./krew-linux_amd64 update
echo 'PATH=${PATH}:${HOME}/.krew/bin' >> ~/.bashrc # 配置环境变量
source ~/.bashrc # 加载环境变量
测试能否正常使用
[root@master ~]# kubectl krew info whoami
NAME: whoami
INDEX: default
URI: https://github.com/rajatjindal/kubectl-whoami/releases/download/v0.0.44/kubectl-whoami_v0.0.44_linux_amd64.tar.gz
SHA256: c5daef9f3f11aa260088eba33e306bbb0b1532ee1a3492f102d0659cd46150d6
VERSION: v0.0.44
HOMEPAGE: https://github.com/rajatjindal/kubectl-whoami
DESCRIPTION:
This plugin show the subject that's currently authenticated as.
设定完成后,kubectl krew子命令便能执行Krew插件管理器的相关功能,例如查找和安装所需要的插件,它拥有help、list、search、info、install、upgrade和uninstall等二级子命令。下面的命令搜索Krew索引中包含字符串who的插件
[root@master ~]# kubectl krew search who
NAME DESCRIPTION INSTALLED
switch-config Switches between kubeconfig files no
view-webhook Visualize your webhook configurations no
who-can Shows who has RBAC permissions to access Kubern... no
whoami Show the subject that's currently authenticated... no