title | weight | catalog | date | subtitle | header-img | tags | catagories | ||
---|---|---|---|---|---|---|---|---|---|
kubectl命令别名 |
3 |
true |
2019-08-13 03:50:57 -0700 |
|
|
kubectl-aliases开源工具是由脚本通过拼接各种kubectl相关元素组成的alias命令别名列表,其中命令别名拼接元素如下:
base | [system?] | [operation] | [resource] | [flags] |
---|---|---|---|---|
k ubectl |
-n=kube-sys tem |
g etd escribe rm :deletelo gsex eca pply |
po dsdep loymentsec reting ressno de svc ns cm |
oyaml ojson owide all w atchf ilel |
k
=kubectl- sys=
--namespace kube-system
- sys=
- commands:
- g=
get
- d=
describe
- rm=
delete
- a:
apply -f
- ex:
exec -i -t
- lo:
logs -f
- g=
- resources:
- po=
pod
- dep=
deployment
- ing=
ingress
- svc=
service
- cm=
configmap
- sec=
secret
- ns=
namespace
- no=
node
- po=
- flags:
- output format: oyaml, ojson, owide
- all:
--all
or--all-namespaces
depending on the command - sl:
--show-labels
- w=
-w/--watch
- value flags (should be at the end):
- f=
-f/--filename
- l=
-l/--selector
- f=
# 示例1
kd → kubectl describe
# 示例2
kgdepallw → kubectl get deployment —all-namespaces —watch
alias get示例:
alias k='kubectl'
alias kg='kubectl get'
alias kgpo='kubectl get pods'
alias kgpoojson='kubectl get pods -o=json'
alias kgpon='kubectl get pods --namespace'
alias ksysgpooyamll='kubectl --namespace=kube-system get pods -o=yaml -l'
# 将 .kubectl_aliases下载到 home 目录
cd ~ && wget https://raw.githubusercontent.com/ahmetb/kubectl-aliases/master/.kubectl_aliases
# 将以下内容添加到 .bashrc中,并执行 source .bashrc
[ -f ~/.kubectl_aliases ] && source ~/.kubectl_aliases
function kubectl() { command kubectl $@; }
# 如果需要提示别名的完整命令,则将以下内容添加到 .bashrc中,并执行 source .bashrc
[ -f ~/.kubectl_aliases ] && source ~/.kubectl_aliases
function kubectl() { echo "+ kubectl $@"; command kubectl $@; }
参考: