Home

Awesome

kubectl-aliases-powershell

Forked from: https://github.com/ahmetb/kubectl-aliases

This repository contains a script to generate hundreds of convenient kubectl PowerShell aliases programmatically.

Examples

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.

Installation

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"

Optional

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; }

Syntax explanation

FAQ

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