最近得知一个kubectl插件安装工具,叫做krew。
官网地址是:Krew – kubectl plugin manager
安装krew
按照官网的做法,一直安装失败,于是拆解步骤,一步一步下载离线安装。
1、下载krew.yaml
地址:https://github.com/kubernetes-sigs/krew-index/blob/master/plugins/krew.yaml
这里我把原文贴出来,大家可以直接copy使用
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:name: krew
spec:version: "v0.4.4"homepage: https://krew.sigs.k8s.io/shortDescription: Package manager for kubectl plugins.caveats: |krew is now installed! To start using kubectl plugins, you need to addkrew'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 variableTo list krew commands and to get help, run:$ kubectl krewFor a full list of available plugins, run:$ kubectl krew searchYou can find documentation athttps://krew.sigs.k8s.io/docs/user-guide/quickstart/.# The supported platforms for plugins are the ones that Krew itself is distributed in.# See all supported platforms on the [releases page](https://github.com/kubernetes-sigs/krew/releases).platforms:- uri: https://github.com/kubernetes-sigs/krew/releases/download/v0.4.4/krew-darwin_amd64.tar.gzsha256: 5f4d2f34868a87cf1188212cf7cb598e76a32f389054089aad1fa46e6daf1e1bbin: krewfiles:- from: ./krew-darwin_amd64to: krew- from: ./LICENSEto: .selector:matchLabels:os: darwinarch: amd64- uri: https://github.com/kubernetes-sigs/krew/releases/download/v0.4.4/krew-darwin_arm64.tar.gzsha256: e6ac776140b228d6bdfda11247baf4e9b11068f42005d0975fc260c629954464bin: krewfiles:- from: ./krew-darwin_arm64to: krew- from: ./LICENSEto: .selector:matchLabels:os: darwinarch: arm64- uri: https://github.com/kubernetes-sigs/krew/releases/download/v0.4.4/krew-linux_amd64.tar.gzsha256: e471396b0ed4f2be092b4854cc030dfcbb12b86197972e7bef0cb89ad9c72477bin: krewfiles:- from: ./krew-linux_amd64to: krew- from: ./LICENSEto: .selector:matchLabels:os: linuxarch: amd64- uri: https://github.com/kubernetes-sigs/krew/releases/download/v0.4.4/krew-linux_arm.tar.gzsha256: 4f3d550227e014f3ba7c72031108ffda0654cb755f70eb96be413a5102d23333bin: krewfiles:- from: ./krew-linux_armto: krew- from: ./LICENSEto: .selector:matchLabels:os: linuxarch: arm- uri: https://github.com/kubernetes-sigs/krew/releases/download/v0.4.4/krew-linux_arm64.tar.gzsha256: f8f0cdbf698ed3e8cb46e7bd213754701341a10e11ccb69c90d4863e0cf5a16abin: krewfiles:- from: ./krew-linux_arm64to: krew- from: ./LICENSEto: .selector:matchLabels:os: linuxarch: arm64- uri: https://github.com/kubernetes-sigs/krew/releases/download/v0.4.4/krew-linux_ppc64le.tar.gzsha256: 966ee6d2b113c9ed7d8c6072ae3b24d5041da9a658b6197249634c5c76ba37a9bin: krewfiles:- from: ./krew-linux_ppc64leto: krew- from: ./LICENSEto: .selector:matchLabels:os: linuxarch: ppc64le- uri: https://github.com/kubernetes-sigs/krew/releases/download/v0.4.4/krew-windows_amd64.tar.gzsha256: da0dfeb2a598f11fb9ce871ee7f3b1a69beb371a45f531ee65a71b2201511d28bin: krew.exefiles:- from: ./krew-windows_amd64.exeto: krew.exe- from: ./LICENSEto: .selector:matchLabels:os: windowsarch: amd64
2、下载安装包
根据官网给的命令中的这一部分,大家执行的时候,可能会出错,但是至少可以看到一个url地址
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-linux_amd64.tar.gz
如下图所示:
3、安装
./krew-linux_amd64 install --manifest=krew.yaml --archive=krew-linux_amd64.tar.gz
4、配置环境变量
vi ~/.bashrc 加入如下内容
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
记得再加载一下环境变量,使其生效
source ~/.bashrc
5、验证
kubectl krew -h