Last active
February 20, 2019 09:24
-
-
Save jondlm/35cbf0363eb925e2eff6ff86c0a30992 to your computer and use it in GitHub Desktop.
Kubernetes Fuzzy Helper Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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