Skip to content

Instantly share code, notes, and snippets.

@srolel
Created May 27, 2018 01:15
Show Gist options
  • Save srolel/d87865d6ed19d7e993762a370be11610 to your computer and use it in GitHub Desktop.
Save srolel/d87865d6ed19d7e993762a370be11610 to your computer and use it in GitHub Desktop.
kubectl shortcuts
kubepods() {
kubectl get pods --all-namespaces | grep $1 | awk '{print "--namespace="$1 " " $2}'
}
kubepod() {
kubepods $1 | head -1
}
kubebash() {
kubectl exec -ti $(kubepod $1) bash
}
kubessh() {
kubebash $1
}
kubesh() {
kubectl exec -ti $(kubepod $1) sh
}
kubelog() {
kubectl logs $(kubepod $1)
}
kubekillall() {
kubectl delete deployment $(kubectl.exe get deployments | grep $1 | head -1 | awk '{print $1}')
kubectl delete service $(kubectl.exe get services | grep $1 | head -1 | awk '{print $1}')
}
kubedesc() {
kubectl describe pod $(kubepod $1)
}
kubeexec() {
kubectl exec -ti $(kubepod $1) $2 -- ${@:3}
}
kubeattach() {
kubectl attach -ti $(kubepod $1)
}
kubecontextname() {
kubectl config view | grep $(gcloud config get-value project -q) | grep $1 | sed -n 1p | awk '{print $2}'
}
kubeusecontext() {
kubectl config use-context $(kubecontextname $1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment