Skip to content

Instantly share code, notes, and snippets.

@jurriaan
Created March 3, 2017 10:41
Show Gist options
  • Save jurriaan/abc85397a81a575968c0a04748ff7d09 to your computer and use it in GitHub Desktop.
Save jurriaan/abc85397a81a575968c0a04748ff7d09 to your computer and use it in GitHub Desktop.
function kns
echo $argv | read -l namespace context
if test -z "$context"
set context (kubectl config current-context)
end
if test -z "$argv"
echo "USAGE: kns NAMESPACE [context]"
else
kubectl config use-context "$context"
kubectl config set-context "$context" --namespace="$namespace"
end
end
function kw
watch --color "kubectl $argv"
end
function __fish_kubectl_get_namespaces
kubectl get ns -oname | awk -F/ '{print $2}'
end
complete -x -c kns -a '(__fish_kubectl_get_namespaces)'
function klog
set namespace (kubectl config get-contexts | grep "^\*" | awk '{print $NF}')
set pattern $argv[1]
set --erase argv[1]
stern -e health -n $namespace $argv $pattern
end
complete -x -c klog -a '(__fish_kubectl_get_deployments)'
function __fish_kubectl_get_deployments
kubectl get deployment -oname | awk -F/ '{print $2}'
end
function kexec
set pod (echo $argv[1] | awk -F/ '{print $1}')
set container (echo $argv[1] | awk -F/ '{print $2}')
if test -n "$container"
kubectl exec -it "$pod" -c "$container" -- env COLUMNS=$COLUMNS LINES=$LINES TERM=xterm $argv[2..-1]
else
kubectl exec -it "$pod" -- env COLUMNS=$COLUMNS LINES=$LINES TERM=xterm $argv[2..-1]
end
end
complete -x -c kexec -a '(__fish_kubectl_get_pods)'
function __fish_kubectl_get_pods
kubectl get pod -oname | awk -F/ '{print $2}'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment