Created
February 29, 2024 00:18
-
-
Save jfarcand/9ca4f7889f205d36987384254923efe8 to your computer and use it in GitHub Desktop.
Get the pod log
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
kl() { | |
local key="$1" | |
local namespace="${2:-production}" # Default to production if no namespace is provided | |
local pod_names | |
local selected_pod | |
# Find the pod names based on the key | |
pod_names=($(kubectl get pod -n "$namespace" | grep "$key" | awk '{print $1}')) | |
if [[ ${#pod_names[@]} -eq 0 ]]; then | |
echo "No pods found with key: $key in namespace: $namespace" | |
return 1 | |
elif [[ ${#pod_names[@]} -eq 1 ]]; then | |
selected_pod=${pod_names[1]} | |
echo "Selected pod: $selected_pod" | |
else | |
echo "Multiple pods found with key: $key in namespace: $namespace" | |
select pod in "${pod_names[@]}"; do | |
selected_pod=$pod | |
break | |
done | |
fi | |
# Get the logs for the selected pod and format them with zap-pretty | |
kubectl logs -n "$namespace" -f "$selected_pod" | zap-pretty | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment