Last active
September 11, 2020 19:01
-
-
Save picaron/642e2ba7a8ffdb61f9e36ea1fd355584 to your computer and use it in GitHub Desktop.
useful kubernetes aliases for using with orchard
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
alias k="kubectl" | |
alias kp="kubectl get pods" | |
alias ks="kubectl get pods" | |
alias kd="kubectl describe pod" | |
function kk() { | |
kubectl config get-contexts | grep '*' | awk '{print "Context:",$2,"\nNamespace:",$5}' | |
} | |
function kc() { | |
if [ -z $1 ]; then | |
echo "No subcommand specified, showing contexts. Use kc --help to see how to use." | |
echo "" | |
kubectl config get-contexts | |
else | |
kubectl config $* | |
fi | |
} | |
function kn() { | |
NAMESPACE="od-$1" | |
shift | |
kubectl config set-context $(kubectl config current-context) --namespace=$NAMESPACE $* | |
kubectl config get-contexts | |
} | |
function kl() { | |
if [ -z $1 ]; then | |
echo "Dude, you gotta tell me which pod (even partial name will do)" | |
echo "" | |
echo "Here are the pods I know in the current context" | |
echo "" | |
kk | |
echo "" | |
kubectl get pods | |
return | |
fi | |
FINDNAME=$1 | |
shift | |
POD=`kubectl get pods | grep $FINDNAME | head -n 1 | awk '{print $1}'` | |
kubectl logs $POD $* | |
} | |
function kf() { | |
if [ -z $1 ]; then | |
echo "Dude, you gotta tell me which pod (even partial name will do)" | |
echo "" | |
echo "Here are the pods I know in the current context" | |
echo "" | |
kk | |
echo "" | |
kubectl get pods | |
return | |
fi | |
FINDNAME=$1 | |
shift | |
LOCAL_PORT=$1 | |
shift | |
if [ -z $1 ]; then | |
REMOTE_PORT=$LOCAL_PORT | |
else | |
REMOTE_PORT=$1 | |
shift | |
fi | |
POD=`kubectl get pods | grep $FINDNAME | head -n 1 | awk '{print $1}'` | |
echo "Forwarding port $LOCAL_PORT to $POD:$REMOTE_PORT ... (press CTRL-C twice to abort)" | |
while true | |
do | |
kubectl port-forward $POD $LOCAL_PORT:$REMOTE_PORT $* | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment