二进制部署k8s教程05 - 操作命令别名

2023-03-08 21:14:15 浏览数 (1)

!TIP 二进制部署 k8s - 实用命令别名


转载请注明出处:https://janrs.com/6qdr 有任何问题欢迎在底部评论区发言。

k8s 命令别名

部署期间不停的重启服务,查看日志,查看 k8s 部署情况。打命令打到手指断掉。

一怒之下整理了常用命令别名。

kubectl 常用命令别名

代码语言:shell复制
cat > /etc/profile.d/kubectl_cmd_alias.sh <<EOF

# 设置kubectl常用别名
alias k='kubectl'
alias kg='k get'
alias kdl='k delete -f'
alias kap='k apply -f'
alias kd='k describe'

# pod command
alias kgpo='kg pods'
alias kgpow='kg pods -o wide'
alias kgpoa='kg pods --all-namespaces'
alias kgpoaf='kg pods --all-namespaces | grep '
alias kgpon='kg pods -n '
alias kgpoaw='kg pods --all-namespaces -o wide'
alias kdpo='kd pod'

# namespace command
alias kgns='kg ns'

# service command
alias kgsvca='kg svc --all-namespaces'
alias kgsvc='kg svc'
alias kdsvc='kd svc'

# ingress command
alias kgia='kg ingress --all-namespaces'
alias kgi='kg ingress'

# endpoint command
alias kgepa='kg ep --all-namespaces'
alias kgep='kg ep'

#kubectl describe ep
alias kdep='kd ep'

# node command
alias kgn='kg nodes'
alias kgnl='kg nodes --show-labels'
alias kdn='kd nodes'

# deploy command
alias kgdpa='kg deploy --all-namespaces'
alias kgdp='kg deploy'
alias kddp='kd deploy'

EOF
source /etc/profile

master 组件常用命令别名

代码语言:shell复制
cat > /etc/profile.d/master_cmd_alias.sh <<EOF

alias restartapi='systemctl daemon-reload && systemctl restart kube-apiserver'
alias restartcontroller='systemctl daemon-reload && systemctl restart kube-controller-manager'
alias restartscheduler='systemctl daemon-reload && systemctl restart kube-scheduler'

alias startapi='systemctl daemon-reload && systemctl start kube-apiserver'
alias startcontroller='systemctl daemon-reload && systemctl start kube-controller-manager'
alias startscheduler='systemctl daemon-reload && systemctl start kube-scheduler'

alias stopapi='systemctl daemon-reload && systemctl stop kube-apiserver'
alias stopcontroller='systemctl daemon-reload && systemctl stop kube-controller-manager'
alias stopscheduler='systemctl daemon-reload && systemctl stop kube-scheduler'

# 获取组件运行状态以及日志
alias kgapis='echo -e "'"nnn"'" && systemctl status kube-apiserver -n 10 --no-pager -l && echo -e "'"n"'"'
alias kgapisl='echo -e "'"nnn"'" && systemctl status kube-apiserver --no-pager -l && echo -e "'"n"'"'

alias kgcontrollers='echo -e "'"nnn"'" && systemctl status kube-controller-manager -n 10 --no-pager -l && echo -e "'"n"'"'
alias kgcontrollersl='echo -e "'"nnn"'" && systemctl status kube-controller-manager --no-pager -l && echo -e "'"n"'"'

alias kgschedulers='echo -e "'"nnn"'" && systemctl status kube-scheduler -n 10 --no-pager -l && echo -e "'"n"'"'
alias kgschedulersl='echo -e "'"nnn"'" && systemctl status kube-scheduler --no-pager -l && echo -e "'"n"'"'


alias kgapilog='echo -e "'"nnn"'" && journalctl -n 100 -l --no-pager  -u kube-apiserver && echo -e "'"n"'"'
alias kgcontrollerlog='echo -e "'"nnn"'" && journalctl -n 100 -l --no-pager  -u kube-controller-manager && echo -e "'"n"'"'
alias kgschedulerlog='echo -e "'"nnn"'" && journalctl -n 100 -l --no-pager  -u kube-scheduler && echo -e "'"n"'"'

alias kgapierr='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/apiserver/kube-apiserver.ERROR && echo -e "'"n"'"'
alias kgapiinfo='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/apiserver/kube-apiserver.INFO && echo -e "'"n"'"'
alias kgapiwar='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/apiserver/kube-apiserver.WARNING && echo -e "'"n"'"'
alias kgapifatal='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/apiserver/kube-apiserver.FATAL && echo -e "'"n"'"'

alias kgcontrollererr='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/controller/kube-controller-manager.ERROR && echo -e "'"n"'"'
alias kgcontrollerinfo='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/controller/kube-controller-manager.INFO && echo -e "'"n"'"'
alias kgcontrollerwar='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/controller/kube-controller-manager.WARNING && echo -e "'"n"'"'
alias kgcontrollerfatal='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/controller/kube-controller-manager.FATAL && echo -e "'"n"'"'

alias kgschedulererr='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/scheduler/kube-scheduler.ERROR && echo -e "'"n"'"'
alias kgschedulerinfo='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/scheduler/kube-scheduler.INFO && echo -e "'"n"'"'
alias kgschedulerwar='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/scheduler/kube-scheduler.WARNING && echo -e "'"n"'"'
alias kgschedulerfatal='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/scheduler/kube-scheduler.FATAL && echo -e "'"n"'"'

EOF
source /etc/profile

node 组件常用命令别名

代码语言:shell复制
cat > /etc/profile.d/node_cmd_alias.sh <<EOF

alias restartkubelet='systemctl daemon-reload && systemctl restart kubelet'
alias restartproxy='systemctl daemon-reload && systemctl restart kube-proxy'

alias startkubelet='systemctl daemon-reload && systemctl start kubelet'
alias startproxy='systemctl daemon-reload && systemctl start kube-proxy'

alias stopkubelet='systemctl stop kubelet'
alias stopproxy='systemctl stop kube-proxy'

# 获取组件运行状态以及日志
alias kgkubelets='echo -e "'"nnn"'" && systemctl status kubelet -n 10 --no-pager -l && echo -e "'"n"'"'
alias kgkubeletsl='echo -e "'"nnn"'" && systemctl status kubelet -n 10 --no-pager -l && echo -e "'"n"'"'

alias kgproxys='echo -e "'"nnn"'" && systemctl status kube-proxy -n 10 --no-pager -l && echo -e "'"n"'"'
alias kgproxysl='echo -e "'"nnn"'" && systemctl status kube-proxy -n 10 --no-pager -l && echo -e "'"n"'"'

alias kgkubeletlog='echo -e "'"nnn"'" && journalctl -n 100 -l --no-pager  -u kubelet && echo -e "'"n"'"'
alias kgproxylog='echo -e "'"nnn"'" && journalctl -n 100 -l --no-pager  -u kube-proxy && echo -e "'"n"'"'

alias kgkubeleterr='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/kubelet/kubelet.ERROR && echo -e "'"n"'"'
alias kgkubeletinfo='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/kubelet/kubelet.INFO && echo -e "'"n"'"'
alias kgkubeletfatal='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/kubelet/kubelet.FATAL && echo -e "'"n"'"'
alias kgkubeletwar='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/kubelet/kubelet.WARNING && echo -e "'"n"'"'


alias kgproxyerr='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/kube-proxy/kube-proxy.ERROR && echo -e "'"n"'"'
alias kgproxyinfo='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/kube-proxy/kube-proxy.INFO && echo -e "'"n"'"'
alias kgproxyfatal='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/kube-proxy/kube-proxy.FATAL && echo -e "'"n"'"'
alias kgproxywar='echo -e "'"nnn"'" && tail -n 30 /var/log/kubernetes/kube-proxy/kube-proxy.WARNING && echo -e "'"n"'"'

EOF
source /etc/profile

转载请注明出处:https://janrs.com/6qdr 有任何问题欢迎在底部评论区发言。

0 人点赞