This repository contains a script to generate hundreds ofconvenient shell aliases for kubectl, so you no longer need to spell out every singlecommand and --flag over and over again.
An example shell alias created from command/flags permutation looks like:
alias ksysgdepwslowidel='kubectl --namespace=kube-system get deployment --watch --show-labels -o=wide -l'
Confused? Read on.
Some of the 800 generated aliases are:
alias k='kubectl'
alias kg='kubectl get'
alias kgpo='kubectl get pod'
alias ksysgpo='kubectl --namespace=kube-system get pod'
alias krm='kubectl delete'
alias krmf='kubectl delete -f'
alias krming='kubectl delete ingress'
alias krmingl='kubectl delete ingress -l'
alias krmingall='kubectl delete ingress --all-namespaces'
alias kgsvcoyaml='kubectl get service -o=yaml'
alias kgsvcwn='watch kubectl get service --namespace'
alias kgsvcslwn='watch kubectl get service --show-labels --namespace'
alias kgwf='watch kubectl get -f'
...
See the full list.
You can directly download the .kubectl_aliases
file for bash/zsh or the .kubectl_aliases.fish
file for fish and save it to your $HOME directory.
Add the following to your .bashrc/.zshrc
file:
[ -f ~/.kubectl_aliases ] && source ~/.kubectl_aliases
Recommendation: If you want to use GNU
watch
command instead ofkubectl [...] --watch
, run it like this:[ -f ~/.kubectl_aliases ] && source \ <(cat ~/.kubectl_aliases | sed -r 's/(kubectl.*) --watch/watch \1/g')
Print the full command before running it: Add this to your .bashrc
or.zshrc
file:
function kubectl() { echo "+ kubectl $@">&2; command kubectl $@; }
Add the following to your ~/.config/fish/config.fish
file:
test -f ~/.kubectl_aliases.fish && source ~/.kubectl_aliases.fish
Recommendation: If you want to use GNU
watch
command instead ofkubectl [...] --watch
, run it like this:test -f ~/.kubectl_aliases.fish && source \ (cat ~/.kubectl_aliases.fish | sed -r 's/(kubectl.*) --watch/watch \1/g' | psub)
k
=kubectl
sys
=--namespace kube-system
g
=get
d
=describe
rm
=delete
a
:apply -f
ak
:apply -k
k
:kustomize
ex
: exec -i -t
lo
: logs -f
po
=pod, dep
=deployment
, ing
=ingress
,svc
=service
, cm
=configmap
, sec
=secret
,ns
=namespace
, no
=node
**
oyaml
, ojson
, owide
all
: --all
or --all-namespaces
depending on the commandsl
: --show-labels
w
=-w/--watch
n
=-n/--namespace
f
=-f/--filename
l
=-l/--selector
The script has only one optional argument, the shell to which the aliases will be generated. If not given, it assumes bash
. Ex:
# Generate aliases for bash/zsh
python generate_aliases.py > .kubectl_aliases
# Generate abbr for fish
python generate_aliases.py fish > .kubectl_aliases.fish
Doesn't this slow down my shell start up? Sourcing the file that contains~500 aliases takes about 30-45 milliseconds in my shell (zsh). I don't thinkit's a big deal for me. Measure it with echo $(($(date +%s%N)/1000000))
command yourself in your .bashrc/.zshrc.
Can I add more Kubernetes resource types to this? Please consider forkingthis repo and adding the resource types you want. Not all resource types areused by everyone, and adding more resource types slows down shell initializationsee above).
Where can I find PowerShell aliases for kubectl? There’s a fork of thishere.
This is not an official Google project.
Kubectl 是 Kubernetes 最重要的命令行工具。在 Flant,我们会在 Wiki 和 Slack 上相互分享 Kubectl 的妙用(其实我们还有个搜索引擎,不过那就是另外一回事了)。多年以来,我们在 kubectl 方面积累了很多技巧,现在想要将其中的部分分享给社区。 我相信很多读者对这些命令都非常熟悉;然而我还是希望读者能够从本文中有所获益,进而提高生产力。 下列内容有的是来自
1.结合kubectl部署,加强了解kubectl config命令 kubectl config命令,生成集群信息,集群用户和用户权限并把这些内容写入kubectl读取的配置文件 部署kubectl时执行的kubectl config命令,见下 [root@k8s-master admin]# source /opt/k8s/bin/environment.sh # 设置集群参数 [root@k
发布一个k8s部署视频:https://edu.csdn.net/course/detail/26967 课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。 腾讯课堂连接地址https://ke.qq.com/course/478827?taid=437310993146
1.结合kubectl部署,加强了解kubectl config命令 kubectl config命令,生成集群信息,集群用户和用户权限并把这些内容写入kubectl读取的配置文件 部署kubectl时执行的kubectl config命令,见下 [root@k8s-master admin]# source /opt/k8s/bin/environment.sh # 设置集群参数 [root@k
1. 首先get svc kubectl get svc --all-namespaces 准备修改这个服务 kube-ops jenkins NodePort 10.105.29.106 <none> 8080:30003/TCP,50000:50000/TCP kubectl edit svc/jenkins -n kube-ops 编辑
kubectl-slice 是一个 CLI 工具,可以通过规则将包含多个对象资源的 Kubernetes 配置清单切割成多个 YAML 文件。 例如下面的配置清单: apiVersion: v1kind: Podmetadata: name: nginx-ingress---apiVersion: v1kind: Namespacemetadata: name: production 通过 k
Kubectl-fzf kubectl-fzf provides a fast and powerful fzf autocompletion for kubectl. Table of Contents Kubectl-fzf Table of Contents Features Requirements Installation Cache builder Local installation
kubectl-trace 是一个 kubectl 插件,它可以使用基于 bpftrace 的编程能力,来分析系统的性能问题。你只需编写好程序文件,就可以通过这个插件将其运行到 K8s 集群中,不需要任何额外工作。 架构
Kubectl-debug 简体中文 Overview kubectl-debug is an out-of-tree solution for troubleshooting running pods, which allows you to run a new container in running pods for debugging purpose (examples). The new
kubectl-alias是一个可以帮助你在kubectl上添加常用别名(alias)的插件。 使用示例 # "v" for versionkubectl alias v versionkubectl v --client 安装 Homebrew 安装Homebrew。 brew install predatorray/brew/kubectl-alias 将下面一行添加到rc文件中。 expor
null 我的问题是 为什么在一个集群中有三个操作来执行相同的任务? 这些操作的用例是什么? 他们在引擎盖下有什么不同?