Skip to content

Instantly share code, notes, and snippets.

@miraculixx
Last active August 12, 2023 07:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miraculixx/a347b91c83946d48cf0680713d0cb2a1 to your computer and use it in GitHub Desktop.
Save miraculixx/a347b91c83946d48cf0680713d0cb2a1 to your computer and use it in GitHub Desktop.
useful kubectl shortcuts
# put in $HOME/.bash_k8s.rc
# . $HOME/bash_k8s.rc
# podlog <any pod name substring>
function podlog() {
pod=`kubectl get pods --all-namespaces | grep " $1" | tr -s ' ' | cut -d ' ' -f 2 | head -n1`
ns=`kubectl get pods --all-namespaces | grep " $1" | tr -s ' ' | cut -d ' ' -f 1 | head -n1`
shift 1
kubectl logs --namespace $ns $pod $*
}
# exec a command in a pod, defaults to bash
function podssh() {
pod=`kubectl get pods --all-namespaces | grep " $1" | tr -s ' ' | cut -d ' ' -f 2 | head -n1`
ns=`kubectl get pods --all-namespaces | grep " $1" | tr -s ' ' | cut -d ' ' -f 1 | head -n1`
shift 1
cmd=${@:-bash}
kubectl exec -it --namespace $ns $pod -- $cmd
}
# get a list of pods
function pods() {
kubectl get pods
}
# get a list of services
function svcs {
kubectl get services
}
# describe something
function kdes() {
kubectl describe $*
}
# get cluster info
alias kinfo="kubectl cluster-info"
# shortcut to kubectl
alias k="kubectl"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment