惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Spread Privacy
Spread Privacy
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
DataBreaches.Net
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
L
LangChain Blog
Jina AI
Jina AI
MongoDB | Blog
MongoDB | Blog
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
T
Threatpost
V
V2EX
Security Archives - TechRepublic
Security Archives - TechRepublic
GbyAI
GbyAI
Scott Helme
Scott Helme
Cyberwarzone
Cyberwarzone
H
Help Net Security
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
T
Tenable Blog
S
Schneier on Security
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
F
Full Disclosure
腾讯CDC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security @ Cisco Blogs
A
Arctic Wolf
S
Securelist
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tor Project blog
The Register - Security
The Register - Security
L
LINUX DO - 最新话题
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
L
LINUX DO - 热门话题
TaoSecurity Blog
TaoSecurity Blog
Y
Y Combinator Blog
博客园 - 三生石上(FineUI控件)
C
CERT Recently Published Vulnerability Notes

二丫讲梵

学习周刊-总第258期-2026年第15周 学习周刊-总第257期-2026年第14周 学习周刊-总第256期-2026年第13周 学习周刊-总第255期-2026年第12周 学习周刊-总第254期-2026年第11周 学习周刊-总第253期-2026年第10周 临时插播一条羊毛,免费领取450元大模型API代金券 学习周刊-总第252期-2026年第09周 学习周刊-总第251期-2026年第08周 学习周刊-总第250期-2026年第07周 学习周刊-总第249期-2026年第06周 诚邀评论,聊聊你所知欲知的我 学习周刊-总第248期-2026年第05周 我的QQ动态之2015年 我的QQ动态之2014年 我的QQ动态之2013年 我的QQ动态之2012年 我的QQ动态-2010-2011年 我的QQ动态-创栏小叙 学习周刊-总第247期-2026年第04周 Nexus社区版权益阉割--一文告诉你有哪些版本可以选择 学习周刊-总第246期-2026年第03周 学习周刊-总第245期-2026年第02周 学习周刊-总第244期-2026年第01周 学习周刊-总第243期-2025年第52周 学习周刊-总第242期-2025年第51周 开源项目ZenOps:带你领略禅意运维 学习周刊-总第241期-2025年第50周 用京东金融,享负债人生 学习周刊-总第240期-2025年第49周 学习周刊-总第239期-2025年第48周 整理我在静态服务透明代理上的极致求索之路,最后一个你绝想不到 学习周刊-总第238期-2025年第47周 我们输了,但收获颇多 太多了,太多了 学习周刊-总第237期-2025年第46周 学习周刊-总第236期-2025年第45周 学习周刊-总第235期-2025年第44周 二五年国庆二三事 学习周刊-总第234期-2025年第43周 学习周刊-总第233期-2025年第42周 学习周刊-总第232期-2025年第41周 学习周刊-总第231期-2025年第40周 学习周刊-总第230期-2025年第39周 西湖毅行 2025年开源世界逸闻三则 学习周刊-总第229期-2025年第38周 手抄《与妻书》 CNB开发与构建基于docker-cache缓存复用的配置实践心得 学习周刊-总第228期-2025年第37周 父亲善行录 学习周刊-总第227期-2025年第36周 带你认识我之看看我的高中同学录(其二) 学习周刊-总第226期-2025年第35周 带你认识我之看看我的高中同学录(其一) 认识神级MCP工具系列--用anyquery和数据库交互 学习周刊-总第225期-2025年第34周 学习周刊-总第224期-2025年第33周 学习周刊-总第223期-2025年第32周 学习周刊-总第222期-2025年第31周 学习周刊-总第221期-2025年第30周 CNB云原生开发环境届的瑞士军刀,详解qifei项目 vuepress-vdoing主题配置自建不蒜子统计 学习周刊-总第220期-2025年第29周 写在博客发表文章1000篇的节点 从claude cli的体验聊聊最大的敌人是我们自己的成见 学习周刊-总第219期-2025年第28周 学习周刊-总第218期-2025年第27周 学习周刊-总第217期-2025年第26周 理论正确,事实错误 学习周刊-总第216期-2025年第25周 学习周刊-总第215期-2025年第24周 学习周刊-总第214期-2025年第23周 学习周刊-总第213期-2025年第22周 学习周刊-总第212期-2025年第21周 从赵心童世锦赛夺冠聊聊我的斯诺克情缘 学习周刊-总第211期-2025年第20周 记录二五年五一之短暂回归家庭 学习周刊-总第210期-2025年第19周 学习周刊-总第209期-2025年第18周 学习周刊-总第208期-2025年第17周 Go开发实践之Gin框架将前端的dist目录embed到二进制 学习周刊-总第207期-2025年第16周 近期关于cobra库的一些实践心得总结 学习周刊-总第206期-2025年第15周 我的嗜好--嗑瓜子 记大宝参加幼儿园组织的清明烈士陵园扫墓活动 学习周刊-总第205期-2025年第14周 学习周刊-总第204期-2025年第13周 前端开发小笔记--在数组中给字段添加值与删除字段的操作 学习周刊-总第203期-2025年第12周 人生实苦,何以自渡 学习周刊-总第202期-2025年第11周 近期发现的一些优秀的工具提名(一) 学习周刊-总第201期-2025年第10周 学习周刊-总第200期-2025年第09周 记一次女友喝醉使我忍术破功 爱情风波--一次分手又复合的经历 学习周刊-总第199期-2025年第08周 整理我的信息源
kubectl-krew插件离线安装方案(保你成功)
二丫讲梵 · 2024-04-08 · via 二丫讲梵

# 简介

Krew 本身是一个 kubectl 的插件,同时也是一个 kubectl 的插件包管理器。

借助 Krew,可以轻松地使用 kubectl plugin:发现插件、安装和管理插件。使用类似 apt、dnf 或者 brew。

截至今日,社区已有 242 个插件 (opens new window),借助这些插件,能够实现很多个性的需求。

# 链接

# 离线安装 krew

krew 是个好东西,它之所以在国内不够盛行,应该与受限于网络环境导致安装比较费劲儿有很大关系。因为 krew 自身以及插件的安装都是从 github 下载资源,大多数国内的 k8s 集群可能访问 github 都是比较费劲儿的,所以本文就来介绍一下如何离线安装 krew 及其插件。

# 准备离线资源

很多文章介绍的离线资源,仍旧是通过 github 下载之后获取到,然后再传到服务器进行安装,而有一些朋友可能本地连 github 也是有一些困难的,考虑到这一层原因,我特地把当前 krew 最新版本的包封装到镜像内,便于你直接拿到。

$ docker run -itd --name krew registry.cn-hangzhou.aliyuncs.com/eryajf/pack:krew

1

可以看下我在包里准备的文件:

$ docker exec -it krew tree
.
├── Dockerfile
├── krew-darwin_amd64.tar.gz
├── krew-darwin_arm64.tar.gz
├── krew-linux_amd64.tar.gz
├── krew-linux_arm.tar.gz
├── krew-linux_arm64.tar.gz
├── krew.yaml
├── ns.yaml
└── v0.9.5.tar.gz

1
2
3
4
5
6
7
8
9
10
11

准备了几个常见平台的安装包,这里不多赘述,你选择符合你的平台的包即可。最后的两个文件是插件 ns 对应的配置文件及安装包。

我这里以 linux_amd64 为例,将所需资源拷贝到本地:

$ docker cp krew:/app/krew.yaml ./
$ docker cp krew:/app/krew-linux_amd64.tar.gz ./
$ tar xf krew-linux_amd64.tar.gz

1
2
3

# 执行安装

$ ./krew-linux_amd64 install --manifest=krew.yaml --archive=krew-linux_amd64.tar.gz
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/.
 | /
/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# 添加 krew 到环境变量

将如上输出中的变量写入到环境变量中,我一般写入到 /etc/profile

$ tail -n1 /etc/profile
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

# 加载变量
$ source /etc/profile

1
2
3
4
5

# 验证是否生效

$ kubectl krew  -h
krew is the kubectl plugin manager.
You can invoke krew through kubectl: "kubectl krew [command]..."

Usage:
  kubectl krew [command]

1
2
3
4
5
6

有这个输出则说明生效了。

# 离线安装插件

先介绍一下插件安装的思路,在 plugins (opens new window) 目录下是所有插件的安装信息,拿 ns 插件举例,我们下载他的 yaml,然后可以过滤出安装包的地址:

$ cat ns.yaml | grep uri
    uri: https://github.com/ahmetb/kubectx/archive/v0.9.5.tar.gz

1
2

通过这个地址下载对应的安装包,然后执行如下命令即可离线安装该插件:

$ kubectl krew install --manifest=ns.yaml --archive=v0.9.5.tar.gz

1

那上边我提供的安装包里也准备了这个插件,你可以直接拷贝并安装:

$ docker cp krew:/app/ns.yaml ./
$ docker cp krew:/app/v0.9.5.tar.gz ./

# 执行安装
$ kubectl krew install --manifest=ns.yaml --archive=v0.9.5.tar.gz

1
2
3
4
5

执行安装:

$ kubectl krew install --manifest=ns.yaml --archive=v0.9.5.tar.gz
Installing plugin: ns
Installed plugin: ns
\
 | Use this plugin:
 | 	kubectl ns
 | Documentation:
 | 	https://github.com/ahmetb/kubectx
 | 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.
 | /
/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

然后执行如下命令可以验证安装情况:

$ kubectl ns
app
cattle-system
crane-system
default
kube-node-lease
kube-public
kube-system
tcr-assistant-system

1
2
3
4
5
6
7
8
9

ns 插件就是提供列出命名空间功能的一个插件。

好啦,现在就成功安装了 krew 并演示了一个插件的安装,后续你遇到其他优秀的插件,就可以通过这个思路进行安装啦。