当前位置:网站首页>扩展你的KUBECTL功能
扩展你的KUBECTL功能
2022-07-04 19:28:00 【InfoQ】
kubectl
kubectl
get
proxy
kubectl
kubectl
kubectl
kubectl
kubectl
git
krew
kubectl
- 在终端执行(Bash或者Zsh)执行
(
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}.tar.gz" &&
./"${KREW}" install krew
)
- 将$HOME/.krew/bin加入到PATH环境变量,更新你的.bashrc或者.zshrc文件,添加下面一行
export PATH="${KREW_ROOT:-$HOME/.brew}/bin:$PATH"
- 测试krew已经安装成功
* k krew version
OPTION VALUE
GitTag v0.4.3
GitCommit dbfefa5
IndexURI https://github.com/kubernetes-sigs/krew-index.git
BasePath /home/mengz/.krew
IndexPath /home/mengz/.krew/index/default
InstallPath /home/mengz/.krew/store
BinPath /home/mengz/.krew/bin
DetectedPlatform linux/amd64
- (可选)设置 krew 别名
alias krew='kubectl-krew'
echo "alias krew='kubectl-krew'" >> ~/.alias
kubectl
krew
krew
krew
- 列出当前已安装的插件
* krew list
PLUGIN VERSION
krew v0.4.3
- 安装插件(下面介绍的其他插件将使用这个方式安装)
* krew install [插件名]
- 更新本地插件索引(查看是否有插件更新)
* krew update
Updated the local copy of plugin index.
New plugins available:
* liqo
* switch-config
Upgrades available for installed plugins:
* open-svc v2.5.2 -> v2.5.3
* rbac-tool v1.7.1 -> v1.8.0
* rolesum v1.5.1 -> v1.5.5
- 升级插件
* krew upgrade open-svc
Updated the local copy of plugin index.
Upgrading plugin: open-svc
- 删除插件
* krew uninstall [插件名]
kubectl
example
krew install example
example
* k example deploy
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
fleet
krew install fleet
fleet
* k fleet
CLUSTER VERSION NODES NAMESPACES PROVIDER API
homek8sc1 v1.23.8 3/3 4 ? https://k8sc1.mengz.lan:6443
api-sandbox-x8i5-p1-openshiftapps-com:6443 v1.23.5+9ce5071 ? ? ? https://api.sandbox.x8i5.p1.openshiftapps.com:6443
minikube v1.22.3 1/1 4 minikube https://192.168.64.3:8443
get-all
krew install get-all
get-all
* k get-all -n kube-system
NAME NAMESPACE AGE
configmap/calico-config kube-system 13d
configmap/coredns kube-system 13d
configmap/extension-apiserver-authentication kube-system 13d
configmap/kube-proxy kube-system 13d
configmap/kube-root-ca.crt kube-system 13d
configmap/kubeadm-config kube-system 13d
configmap/kubelet-config-1.23 kube-system 13d
endpoints/kube-dns kube-system 13d
...
htpasswd
krew install htpasswd
htpasswd
* k htpasswd create aaa-basic-auth user1=user1password user2=user2password -o yaml --dry-run
apiVersion: v1
data:
auth: dXNlcjE6JDJhJDEwJDVNeEJGT3lEUEJYT0xkUldlblNWME91RGtZTzFQOElJNXJuRnh5blpUdC55L2FUUUNDYzJ1CnVzZXIyOiQyYSQxMCRVbFdHOG5NTU4zRGVpOC5GMmVRM3EuYWhxTENYZGtLYUJ1cXZzT3lEOGl0ODJRdU4zV1c1dQ==
kind: Secret
metadata:
creationTimestamp: null
name: aaa-basic-auth
namespace: default
type: Opaque
images
krew install images
images
* k images
[Summary]: 1 namespaces, 2 pods, 2 containers and 1 different images
+------------------------+---------------+-------------------+
| PodName | ContainerName | ContainerImage |
+------------------------+---------------+-------------------+
| webapp-98f7444c5-8772w | nginx | nginx:1.21-alpine |
+------------------------+ + +
| webapp-98f7444c5-vsxr9 | | |
+------------------------+---------------+-------------------+
ktop
krew install ktop
ktop
* k ktop
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
│ API server: https://k8sc1.mengz.lan:6443 Version: v1.23.8 context: [email protected] User: kubernetes-admin namespace: (all) metrics: not connected v0.3.0
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
╔ Cluster Summary ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═
║ ptime: 13d Nodes: 3 Namespaces: 4 Pods: 15/15 (20 imgs) Deployments: 5/5 Sets: replicas 5, daemons 6, stateful 0 Jobs: 0 (cron: 0) PVs: 0 (0Gi) PVCs: 0 (0Gi)
║ PU: [||||||||||| ] 1600m/6000m (26.7% requested) Memory: [|| ] 1Gi/11Gi (2.5% requested)
╚ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═
┌ Nodes (3) ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
│ NAME STATUS AGE VERSION INT/EXT IPs OS/ARC PODS/IMGs DISK CPU MEM
│ homek8sc1-control Ready 13d v1.23.8 192.168.0.140/<none> Ubuntu 20.04.4 LTS/amd64 9/10 16Gi [|||||| ] 1100m/2000m (55%) [|| ] 1Gi/2Gi (13%)
│ homek8sc1-worker1 Ready 13d v1.23.8 192.168.0.141/<none> Ubuntu 20.04.4 LTS/amd64 3/5 16Gi [|| ] 250m/2000m (12%) [ ] 0Gi/5Gi (0%)
│ homek8sc1-worker2 Ready 13d v1.23.8 192.168.0.142/<none> Ubuntu 20.04.4 LTS/amd64 3/5 16Gi [|| ] 250m/2000m (12%) [ ] 0Gi/5Gi (0%)
│
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
┌ Pods (15) ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ AMESPACE POD READY STATUS RESTARTS AGE VOLS IP NODE CPU MEMORY
│ ube-system kube-controller-manager-homek8sc1-control 1/1 Running 1 13d 8/8 192.168.0.140 homek8sc1-control [| ] 200m 10.0% [ ] 0Gi 0.0%
│ ube-system kube-proxy-4c9nq 1/1 Running 2 13d 4/4 192.168.0.141 homek8sc1-worker1 [ ] 0m 0.0% [ ] 0Gi 0.0%
│ ube-system kube-proxy-4whcn 1/1 Running 1 13d 4/4 192.168.0.140 homek8sc1-control [ ] 0m 0.0% [ ] 0Gi 0.0%
│ ube-system kube-proxy-bz8lt 1/1 Running 3 13d 4/4 192.168.0.142 homek8sc1-worker2 [ ] 0m 0.0% [ ] 0Gi 0.0%
│ ube-system kube-scheduler-homek8sc1-control 1/1 Running 1 13d 1/1 192.168.0.140 homek8sc1-control [| ] 100m 5.0% [ ] 0Gi 0.0%
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
总结
krew
- https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
- https://krew.sigs.k8s.io/docs/user-guide/quickstart/
边栏推荐
- 九齐单片机NY8B062D单按键控制4种LED状态
- Fleet tutorial 08 introduction to AppBar toolbar Basics (tutorial includes source code)
- Hash quiz game system development how to develop hash quiz game system development (multiple cases)
- Jekins initialization password not found or not found
- GVM使用
- Cdga | six principles that data governance has to adhere to
- hash 表的概念及应用
- 强化学习-学习笔记2 | 价值学习
- What should I do if my computer sharing printer refuses access
- Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法
猜你喜欢
MySQL中的日期时间类型与格式化方式
FS8B711S14电动红酒开瓶器单片机IC方案开发专用集成IC
太方便了,钉钉上就可完成代码发布审批啦!
How does win11 search for wireless displays? Win11 method of finding wireless display device
Win11U盘拒绝访问怎么办?Win11U盘拒绝访问的有效解决方法
接口设计时的一些建议
一文搞懂Go语言中文件的读写与创建
LeetCode+ 81 - 85 单调栈专题
Four traversal methods of binary tree, as well as the creation of binary tree from middle order to post order, pre order to middle order, pre order to post order, and sequence [specially created for t
Aiming at the "amnesia" of deep learning, scientists proposed that based on similarity weighted interleaved learning, they can board PNAS
随机推荐
CDGA|数据治理不得不坚持的六个原则
Play the music of youth
BFC interview Brief
Win11共享文件打不开怎么办?Win11共享文件打不开的解决方法
Après l'insertion de l'image dans le mot, il y a une ligne vide au - dessus de l'image, et la disposition est désordonnée après la suppression
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
Flet tutorial 06 basic introduction to textbutton (tutorial includes source code)
go笔记(1)go语言介绍以及特点
tcp为啥是三次握手和四次挥手
【ISMB2022教程】图表示学习的精准医疗,哈佛大学Marinka Zitnik主讲,附87页ppt
电脑页面不能全屏怎么办?Win11页面不能全屏的解决方法
实践示例理解js强缓存协商缓存
QT writing the Internet of things management platform 38- multiple database support
Advantages of semantic tags and block level inline elements
js 闭包
What is the development of block hash quiz game system? Hash quiz game system development (case mature)
奏响青春的乐章
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
Jekins initialization password not found or not found
Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案