当前位置:网站首页>扩展你的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/
边栏推荐
- 电脑共享打印机拒绝访问要怎么办
- JS closure
- 强化学习-学习笔记2 | 价值学习
- Length of the longest integrable subarray
- 哈希(Hash)竞猜游戏系统开发功能分析及源码
- 【深度学习】一文看尽Pytorch之十九种损失函数
- What if the WiFi of win11 system always drops? Solution of WiFi total drop in win11 system
- node强缓存和协商缓存实战示例
- Automatic generation of interface automatic test cases by actual operation
- What if win11u disk refuses access? An effective solution to win11u disk access denial
猜你喜欢
NLP, vision, chip What is the development direction of AI? Release of the outlook report of Qingyuan Association [download attached]
字节测试工程师十年经验直击UI 自动化测试痛点
Common verification rules of form components -1 (continuously updating ~)
NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]
Flet tutorial 06 basic introduction to textbutton (tutorial includes source code)
Idea configuration standard notes
What if the WiFi of win11 system always drops? Solution of WiFi total drop in win11 system
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
什么叫内卷?
Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法
随机推荐
#夏日挑战赛#带你玩转HarmonyOS多端钢琴演奏
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
栈:如何实现有效括号的判断?
[today in history] July 4: the first e-book came out; The inventor of magnetic stripe card was born; Palm computer pioneer was born
CDGA|数据治理不得不坚持的六个原则
企业数字化转型最佳实践案例:基于云的数字化平台系统安全措施简介与参考
FS4061A升压8.4V充电IC芯片和FS4061B升压12.6V充电IC芯片规格书datasheet
字节测试工程师十年经验直击UI 自动化测试痛点
浏览器渲染页面过程
go笔记(3)Go语言fmt包的用法
接口设计时的一些建议
二叉树的四种遍历方式以及中序后序、前序中序、前序后序、层序创建二叉树【专为力扣刷题而打造】
什么叫内卷?
关于联邦学习和激励的相关概念(1)
word中插入圖片後,圖片上方有一空行,且删除後布局變亂
What if win11u disk refuses access? An effective solution to win11u disk access denial
Related concepts of federal learning and motivation (1)
Oracle database, numbers Force 2 decimal places to display-Alibaba Cloud
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
Taishan Office Technology Lecture: about the order of background (shading and highlighting)