

GitHub - ahmetb/kubectl-aliases: Programmatically generated and smart kubectl al...
source link: https://github.com/ahmetb/kubectl-aliases
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

kubectl-aliases
This repository contains a script to generate hundreds of convenient shell aliases for kubectl, so you no longer need to spell out every single command 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.
Examples
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='kubectl get service --watch --namespace'
alias kgsvcslwn='kubectl get service --show-labels --watch --namespace'
alias kgwf='kubectl get --watch -f'
...
See the full list.
Installation
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.
Bash/Zsh
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
This actually adds the more powerful fish abbreviations instead of aliases, so that pressing space shows the full command before execution.
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)
Syntax explanation
k
=kubectl
sys
=--namespace kube-system
- commands:
g
=get
d
=describe
rm
=delete
a
:apply -f
ak
:apply -k
k
:kustomize
ex
:exec -i -t
lo
:logs -f
- resources:
po
=pod,dep
=deployment
,ing
=ingress
,svc
=service
,cm
=configmap
,sec
=secret
,ns
=namespace
,no
=node
Please do not suggest new resources here, instead fork the project.
- flags:
- output format:
oyaml
,ojson
,owide
all
:--all
or--all-namespaces
depending on the commandsl
:--show-labels
w
=-w/--watch
- output format:
- value flags (should be at the end):
n
=-n/--namespace
f
=-f/--filename
l
=-l/--selector
Running the script
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 think it'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 forking this repo and adding the resource types you want. Not all resource types are used by everyone, and adding more resource types slows down shell initialization see above).
-
Where can I find PowerShell aliases for kubectl? There’s a fork of this here.
Authors
This is not an official Google project.
Recommend
-
95
-
114
README.md Paris Paris lets you define and apply styles programmatically to Android views, including custom attributes. Apply styles programmatically at any time. Combine mu...
-
130
README.md Programmatically remove backgrounds from your images using the remove.bg api.
-
4
Copy link Collaborator camsteffen co...
-
6
kubectx + kubens: Power tools for kubectl This repository provides both kubectx and kubens tools. Install →
-
13
Copy link Contributor Author nipunn1313 ...
-
6
Remotion is a suite of libraries building a foundation for creating videos programmatically using React. Why create videos in React? Leverage web technologies: Use all of CSS, Canvas, SV...
-
6
If you're not familiar, TypeScript paths allow you to assign an alias to some path in your project. This is especially useful for larger projects. Working...
-
1
mjwhitta commented
-
6
Intro Bellow follows a list of aliases, split between beginner and
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK