Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active February 25, 2024 02:48
Show Gist options
  • Save nicerobot/a0889c02a023f9dd769299fd62437837 to your computer and use it in GitHub Desktop.
Save nicerobot/a0889c02a023f9dd769299fd62437837 to your computer and use it in GitHub Desktop.
#!/bin/zsh
# expects https://github.com/ahmetb/kubectl-aliases
# implements lots of https://kubernetes.io/docs/reference/kubectl/cheatsheet/
alias kgpos='kgpo --sort-by=.metadata.creationTimestamp'
alias kgpoy='kgpo -o yaml'
### config view
alias kcv='k config'
alias kcv='kc view'
### users
alias kusers="kcv -o jsonpath='{.users[*].name}'"
kuser() { kcv -o jsonpath='{.users[?(@.name == "'"${1:-${USER:-$(whoami)}}"'")].user.password}'; }
alias kusers="kcv -o jsonpath='{.users[*].name}'"
kuser() { kcv -o jsonpath='{.users[?(@.name == "'"${1:-${USER:-$(whoami)}}"'")].user.password}'; }
### exec
alias kx='k exec'
alias kxit='kx -it'
kxls() { local rest="${@:2}"; kx ${1:-my-pod} -- ls ${rest:-/}; }
alias kls=kxls
kxlsx() { local rest="${@:3}"; kx ${1:-my-pod} -c ${2:-my-container} -- ls ${rest:-/}; }
### logs
klbl() { local rest="${@:2}"; klo -l name=${1:-my-label} ${rest}; }
klprev() { local rest="${@:2}"; klo ${1} --previous ${rest}; }
klblc() { local rest="${@:3}"; klbl ${1:-my-label} -c ${2:-my-container} ${rest}; }
alias klblcp='klblc --previous'
### port-forward
alias kpf='kubectl port-forward'
kfwd() { kpf ${1:-my-pod} ${2:-8000}:${3:-${2:-8000}}; }
### run
alias kr='k run'
alias krun='kr busybox-test --image=busybox -it --rm --restart=Never --'
alias kash='krun /bin/ash'
### top
alias ktop='k top'
ktpod() { ktop pod ${1:-my-pod} --containers; }
ktnod() { ktop node ${1:-my-node}; }
alias ktnode=ktnod
### attach
alias katt='k attach -i'
### api-resources
alias kapi='k api-resources --sort-by=kind'
alias kapiny='kapi --namespaced=true'
alias kapino='kapi --namespaced=false'
alias kapiw='kapi -o wide'
alias kapir='kapiw --verbs=list,get'
### cluster
alias kcl='k cluster-info'
alias kcld='kcl dump'
### misc
alias kapp='k apply'
alias kdel='k delete'
alias kgen='k --dry-run=client -o yaml' # for creating manifests. e.g. kman run nginx --image=nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment