Skip to content

Instantly share code, notes, and snippets.

@hitman99
Last active November 9, 2022 12:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitman99/eca51e34d5f885b9b81b852b5faf7018 to your computer and use it in GitHub Desktop.
Save hitman99/eca51e34d5f885b9b81b852b5faf7018 to your computer and use it in GitHub Desktop.
kubernetes aliases
## Autoexport kubernetes configs
KUBECONFIG=""
for config in $(ls ~/.kube/*.yaml); do
if [[ ! -z $KUBECONFIG ]]; then
KUBECONFIG=$KUBECONFIG:$config
else
KUBECONFIG=$config
fi
done
export KUBECONFIG=$KUBECONFIG
## Kubeclt aliases
alias kubecc="kubectl config current-context"
alias kubegc="kubectl config get-contexts"
alias kubeuc="kubectl config use-context"
alias kubepo="kubectl get pods"
alias kubesvc="kubectl get svc"
alias kubedepo="kubectl describe po"
alias klogs="kubectl logs"
alias kversion="kubectl version --client"
switch_kubectl(){
if [[ $1 == "" ]]; then
echo "Please provide kubectl version, one of: `get_kubectl_versions`"
return 1
fi
cd ~/bin
ln -s -F "kubectl-$1" kubectl
chmod +x kubectl
}
get_kubectl_versions(){
cd ~/bin
echo $(ls | grep kubectl | cut -f 2 -d '-' | grep -v kubectl) | sed -e "s/[[:space:]]/\\, /g"
}
kubesetns(){
kubectl config set-context --current --namespace="$1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment