Skip to content

Instantly share code, notes, and snippets.

@jondlm jondlm/kdebug.bash
Last active Feb 20, 2019

Embed
What would you like to do?
Kubernetes Fuzzy Helper Scripts
#!/usr/bin/env bash
# vim: set syntax=sh:
set -e
if ! hash kubectl 2>/dev/null; then echo "Please install \`kubectl\` before running this command (https://kubernetes.io/docs/tasks/tools/install-kubectl/)"; exit 1; fi
if ! hash fzf 2>/dev/null; then echo "Please install \`fzf\` before running this command (https://github.com/junegunn/fzf#installation)"; exit 1; fi
selection=`kubectl get pods --all-namespaces | grep -v 'NAMESPACE' | fzf --header "Select a pod..."`
namespace=`echo "$selection" | awk '{ print $1 }'`
pod=`echo "$selection" | awk '{ print $2 }'`
containers=`kubectl -n $namespace get pods $pod -o jsonpath='{range .spec.containers[*]}{@.name}{"\n"}{end}'`
container_count=$((`echo "$containers" | wc -l`))
if [ "$container_count" -gt "1" ]; then
container=`echo "$containers" | fzf --header "Select a container..."`
else
container=$containers
fi
kubectl -n $namespace exec -it $pod -c $container ash ||\
kubectl -n $namespace exec -it $pod -c $container bash ||\
kubectl -n $namespace exec -it $pod -c $container sh
#!/usr/bin/env bash
# vim: set syntax=sh:
set -e
if ! hash kubectl 2>/dev/null; then echo "Please install \`kubectl\` before running this command (https://kubernetes.io/docs/tasks/tools/install-kubectl/)"; exit 1; fi
if ! hash fzf 2>/dev/null; then echo "Please install \`fzf\` before running this command (https://github.com/junegunn/fzf#installation)"; exit 1; fi
selection=`kubectl get pods --all-namespaces | grep -v 'NAMESPACE' | fzf --header "Select a pod to delete..."`
namespace=`echo "$selection" | awk '{ print $1 }'`
pod=`echo "$selection" | awk '{ print $2 }'`
kubectl -n $namespace delete pod $pod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.