Skip to content

Instantly share code, notes, and snippets.

@jdpedrie
Last active January 28, 2022 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdpedrie/89485140d3e54e4b82e4e49a4f30ed29 to your computer and use it in GitHub Desktop.
Save jdpedrie/89485140d3e54e4b82e4e49a4f30ed29 to your computer and use it in GitHub Desktop.
source <(kubectl completion zsh)
alias k='kubectl'
alias kgp='k get pods'
alias kgpw='k get pods --watch'
alias ka="k config current-context"
alias kgs="k get services"
# List pod images
alias kgpi='kubectl get pods -o=jsonpath='\''{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}'\'' | sort'
# Get current context
alias krc='kubectl config current-context'
# List all contexts
alias klc='kubectl config get-contexts -o name | sed "s/^/ /;\|^ $(krc)$|s/ /*/"'
# Change current context
alias kcc='kubectl config use-context "$(klc | fzf -e | sed "s/^..//")"'
alias kbash='kubectl exec -it "$(k get pods -o name | fzf -e | sed "s/^pod\///")" -- bash'
alias ksh='kubectl exec -it "$(k get pods -o name | fzf -e | sed "s/^pod\///")" -- /bin/sh'
alias kl='k logs $(k get pods -o name | fzf -e | sed "s/^pod\///")'
alias klp='k logs $(k get pods -o name | fzf -e | sed "s/^pod\///") --previous'
alias kstop='k scale deployment $(kdepl) --replicas=0'
function kscale() {
depl=$(ksrv)
echo "enter number of replicas"
read replicaCount
kubectl scale deployment $depl --replicas=$replicaCount
}
kdepl() {
kubectl get pods -o name | fzf -e | perl -0777 -pe "s/pod\/(.*)-[\d].*/\1/s"
}
ksrv() {
kubectl get services -o name | fzf -e | sed "s/service\///"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment