Last active
August 12, 2023 07:34
-
-
Save miraculixx/a347b91c83946d48cf0680713d0cb2a1 to your computer and use it in GitHub Desktop.
useful kubectl shortcuts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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