Skip to content

Instantly share code, notes, and snippets.

@hassy
Created April 25, 2018 17:04
Show Gist options
  • Save hassy/b4077c0f6161a468cf26f4b607f538a1 to your computer and use it in GitHub Desktop.
Save hassy/b4077c0f6161a468cf26f4b607f538a1 to your computer and use it in GitHub Desktop.
# Local variables:
# mode: shell-script
# eval: (sh-set-shell "zsh")
# End:
alias k-system='kubectl -n kube-system'
source <(kubectl completion zsh)
function k-context() {
if [[ $# -eq 0 ]]; then
kubectl config get-contexts
else
local context=$(kubectl config get-contexts | tr -d "*" | grep $1 | awk '{print $1}')
kubectl config use-context $context
fi
}
function k-namespace() {
local current_context=$(kubectl config current-context)
kubectl config set-context "$current_context" --namespace="$1" >&2
echo "namespace for $current_context set to $1" >&2
}
function k-pod () {
kubectl get pods | grep $1
}
function k-forward () {
local svcPort=${2:-8000}
kubectl port-forward $(kubectl get pods | grep "$1"| head -n 1 | awk '{print $1}') "$svcPort"
}
function k-shell-new-pod() {
kubectl run my-shell --rm -i --tty --image ${1:-"ubuntu"} -- bash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment