Created
December 11, 2020 14:59
-
-
Save thevtm/9bfef4056337ee4459ee9808db6dfb0b to your computer and use it in GitHub Desktop.
Some usefull kubectl commands
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
# | |
# Some usefull kubectl commands | |
# | |
function kube-find-namespace() { | |
kubectl get namespaces | tail -n +2 | fzf -q "$1" | awk '/(.*)/ {print $1}' | |
} | |
function kube-app-pod() { | |
local namespace | |
namespace=$1 | |
kubectl get pods --field-selector status.phase=Running -n "$namespace" | awk '/(.*)-app-(.*) / {print $1}' | head -n 1 | |
} | |
function kube-rc() { | |
local namespace | |
namespace="$(kube-find-namespace "$1")" | |
local pod | |
pod="$(kube-app-pod "$namespace")" | |
echo "Dropping into rails console on $pod in $namespace" | |
kubectl exec -it "$pod" -n "$namespace" -- rails c | |
} | |
function kube-ssh() { | |
local namespace | |
namespace="$(kube-find-namespace "$1")" | |
local pod | |
pod="$(kube-app-pod "$namespace")" | |
echo "Dropping into bash on $pod in $namespace" | |
kubectl exec -it "$pod" -n "$namespace" bash | |
} | |
function kube-log() { | |
local namespace | |
namespace="$(kube-find-namespace "$1")" | |
local pod | |
pod="$(kube-app-pod "$namespace")" | |
echo "Tailing logs on $pod in $namespace" | |
kubectl logs "$pod" -n "$namespace" -f | |
} | |
alias kssh="kube-ssh" | |
alias krc="kube-rc" | |
alias klog="kube-log" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment