Forked from: https://github.com/ahmetb/kubectl-aliases
This repository contains a script to generate hundreds of convenient kubectl PowerShell aliases programmatically.
Some of the 800 generated aliases are:
function k() { & kubectl $args }
function kg() { & kubectl get $args }
function kgpo() { & kubectl get pods $args }
function ksysgpo() { & kubectl --namespace=kube-system get pods $args }
function krm() { & kubectl delete $args }
function krmf() { & kubectl delete --recursive -f $args }
function krming() { & kubectl delete ingress $args }
function krmingl() { & kubectl delete ingress -l $args }
function krmingall() { & kubectl delete ingress --all $args }
function kgsvcoyaml() { & kubectl get service -o=yaml $args }
function kgsvcwn() { & kubectl get service --watch --namespace $args }
function kgwf() { & kubectl get --watch --recursive -f $args }
...
See the full list.
You can directly download the kubectl_aliases.ps1
file and save it to PowerShell profile directory (you can run the command explorer $(Split-Path -Path $PROFILE)
to go to your profile's directory) then add this line to your profile.ps1
:
. "$(Split-Path -Path $PROFILE)\kubectl_aliases.ps1"
If you want to print the full command before running it, add this to your profile.ps1
file:
function kubectl() { Write-Output "> kubectl $(@($args | ForEach-Object {$_}) -join ' ')"; & kubectl.exe $args; }
k
=kubectl
sys
=--namespace kube-system
- commands:
g
=get
d
=describe
rm
=delete
a
:apply -f
ex
:exec -i -t
lo
:logs -f
- resources:
po
=pod,dep
=deployment
,ing
=ingress
,svc
=service
,cm
=configmap
,sec
=secret
,ns
=namespace
,no
=node
- 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):
f
=-f/--filename
l
=-l/--selector
Does this not slow down my shell start up?
Sourcing the file that contains
~800 aliases takes less than 30 milliseconds on my laptop. Measure it yourself with Measure-Command { . $Home\Documents\WindowsPowerShell\kubectl_aliases.ps1 }
command.
How to regenerate the PowerShell aliases file?
# powershell
python generate_aliases.py --output ps1 | Out-File -Encoding ascii kubectl_aliases.ps1