kubectl 命令自动补全

kubectl 自带的补全

kubectl 的命令补全脚本来实现自动补全提示的方法。这可以大大提高在命令行中使用 kubectl 时的效率。

在 Bash 中,可以通过以下方式加载 kubectl 的命令补全脚本:

source <(kubectl completion bash)
## 加入~/.bashrc
bash ##刷新配置

在 Zsh 中,可以使用以下方式加载 kubectl 的命令补全脚本:

source <(kubectl completion zsh)
## 加入~/.zshrc
zsh ##刷新配置

在这之后,你就可以在终端中输入 kubectl 后按下 Tab 键来进行命令自动补全了。例如,输入 kubectl get p 然后按下 Tab 键,它会自动补全为 kubectl get pods

这是一种非常方便的方法,尤其在你经常使用 kubectl 进行 Kubernetes 操作时。你可以将这些加载命令添加到你的 Shell 配置文件中,以便每次启动 Shell 时都能自动加载。

kubectl   completion -h

可以看自动补全文档

Oh My Zsh 历史命令自动提示

安装 Oh My Zsh

yum install git zsh curl -y


zsh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
#中国区加速
zsh -c "$(curl -fsSL http://qiniu.dywlkj.com/install-omz.sh)"
#安装是询问是否设置默认zsh 选是

 #生效刷新
zsh

安装 zsh-autosuggestions 插件

cd ~/.oh-my-zsh/custom/plugins/
#中国区gitee.com加速
git clone https://gitee.com/XiongMingcai/zsh-autosuggestions.git
# 验证
 omz plugin list |grep autosuggesti
zsh-autosuggestions
## 启用插件
omz plugin enable zsh-autosuggestions

kubectl 命令缩写插件

## 启用
  omz plugin enable kubectl  
## 查看kubectl 缩写命令
  omz plugin info kubectl  
AliasCommandDescription
kkubectlThe kubectl command
kcakubectl --all-namespacesThe kubectl command targeting all namespaces
kafkubectl apply -fApply a YML file
ketikubectl exec -tiDrop into an interactive terminal on a container
Manage configuration quickly to switch contexts between local, dev and staging
kcuckubectl config use-contextSet the current-context in a kubeconfig file
kcsckubectl config set-contextSet a context entry in kubeconfig
kcdckubectl config delete-contextDelete the specified context from the kubeconfig
kccckubectl config current-contextDisplay the current-context
kcgckubectl config get-contextsList of contexts available
General aliases
kdelkubectl deleteDelete resources by filenames, stdin, resources and names, or by resources and label selector
kdelfkubectl delete -fDelete a pod using the type and name specified in -f argument
Pod management
kgpkubectl get podsList all pods in ps output format
kgpwkgp --watchAfter listing/getting the requested object, watch for changes
kgpwidekgp -o wideOutput in plain-text format with any additional information. For pods, the node name is included
kepkubectl edit podsEdit pods from the default editor
kdpkubectl describe podsDescribe all pods
kdelpkubectl delete podsDelete all pods matching passed arguments
kgplkgp -lGet pods by label. Example: kgpl "app=myapp" -n myns
kgpnkgp -nGet pods by namespace. Example: kgpn kube-system
Service management
kgskubectl get svcList all services in ps output format
kgswkgs --watchAfter listing all services, watch for changes
kgswidekgs -o wideAfter listing all services, output in plain-text format with any additional information
keskubectl edit svcEdit services(svc) from the default editor
kdskubectl describe svcDescribe all services in detail
kdelskubectl delete svcDelete all services matching passed argument
Ingress management
kgikubectl get ingressList ingress resources in ps output format
keikubectl edit ingressEdit ingress resource from the default editor
kdikubectl describe ingressDescribe ingress resource in detail
kdelikubectl delete ingressDelete ingress resources matching passed argument
Namespace management
kgnskubectl get namespacesList the current namespaces in a cluster
kcnkubectl config set-context --current --namespaceChange current namespace
kenskubectl edit namespaceEdit namespace resource from the default editor
kdnskubectl describe namespaceDescribe namespace resource in detail
kdelnskubectl delete namespaceDelete the namespace. WARNING! This deletes everything in the namespace
ConfigMap management
kgcmkubectl get configmapsList the configmaps in ps output format
kecmkubectl edit configmapEdit configmap resource from the default editor
kdcmkubectl describe configmapDescribe configmap resource in detail
kdelcmkubectl delete configmapDelete the configmap
Secret management
kgseckubectl get secretGet secret for decoding
kdseckubectl describe secretDescribe secret resource in detail
kdelseckubectl delete secretDelete the secret
Deployment management
kgdkubectl get deploymentGet the deployment
kgdwkgd --watchAfter getting the deployment, watch for changes
kgdwidekgd -o wideAfter getting the deployment, output in plain-text format with any additional information
kedkubectl edit deploymentEdit deployment resource from the default editor
kddkubectl describe deploymentDescribe deployment resource in detail
kdeldkubectl delete deploymentDelete the deployment
ksdkubectl scale deploymentScale a deployment
krsdkubectl rollout status deploymentCheck the rollout status of a deployment
kreskubectl set env $@ REFRESHED_AT=...Recreate all pods in deployment with zero-downtime
Rollout management
kgrskubectl get replicasetList all ReplicaSets rs created by the deployment
kdrskubectl describe replicasetDescribe ReplicaSet in detail
kerskubectl edit replicasetEdit ReplicaSet from the default editor
krhkubectl rollout historyCheck the revisions of this deployment
krukubectl rollout undoRollback to the previous revision
Port forwarding
kpfkubectl port-forwardForward one or more local ports to a pod
Tools for accessing all information
kgakubectl get allList all resources in ps format
kgaakubectl get all --all-namespacesList the requested object(s) across all namespaces
Logs
klkubectl logsPrint the logs for a container or resource
klfkubectl logs -fStream the logs for a container or resource (follow)
File copy
kcpkubectl cpCopy files and directories to and from containers
Node management
kgnokubectl get nodesList the nodes in ps output format
kenokubectl edit nodeEdit nodes resource from the default editor
kdnokubectl describe nodeDescribe node resource in detail
kdelnokubectl delete nodeDelete the node
Persistent Volume Claim management
kgpvckubectl get pvcList all PVCs
kgpvcwkgpvc --watchAfter listing/getting the requested object, watch for changes
kepvckubectl edit pvcEdit pvcs from the default editor
kdpvckubectl describe pvcDescribe all pvcs
kdelpvckubectl delete pvcDelete all pvcs matching passed arguments
StatefulSets management
kgsskubectl get statefulsetList the statefulsets in ps format
kgsswkgss --watchAfter getting the list of statefulsets, watch for changes
kgsswidekgss -o wideAfter getting the statefulsets, output in plain-text format with any additional information
kesskubectl edit statefulsetEdit statefulset resource from the default editor
kdsskubectl describe statefulsetDescribe statefulset resource in detail
kdelsskubectl delete statefulsetDelete the statefulset
kssskubectl scale statefulsetScale a statefulset
krssskubectl rollout status statefulsetCheck the rollout status of a deployment
Service Accounts management
kdsakubectl describe saDescribe a service account in details
kdelsakubectl delete saDelete the service account
DaemonSet management
kgdskubectl get daemonsetList all DaemonSets in ps output format
kgdswkgds --watchAfter listing all DaemonSets, watch for changes
kedskubectl edit daemonsetEdit DaemonSets from the default editor
kddskubectl describe daemonsetDescribe all DaemonSets in detail
kdeldskubectl delete daemonsetDelete all DaemonSets matching passed argument
CronJob management
kgcjkubectl get cronjobList all CronJobs in ps output format
kecjkubectl edit cronjobEdit CronJob from the default editor
kdcjkubectl describe cronjobDescribe a CronJob in details
kdelcjkubectl delete cronjobDelete the CronJob
Job management
kgjkubectl get jobList all Job in ps output format
kejkubectl edit jobEdit a Job in details
kdjkubectl describe jobDescribe the Job
kdeljkubectl delete jobDelete the Job
  • 29
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值