Created
March 6, 2023 23:15
-
-
Save navicore/4169eb3f7f4789db3b432c80e591de17 to your computer and use it in GitHub Desktop.
kubectl logs bash deployments
This file contains hidden or 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 | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 DEPLOYMENT_NAME" | |
exit 1 | |
fi | |
DEPLOYMENT_NAME="$1" | |
LOG_DIR="./logs" | |
# Create the logs directory if it doesn't exist | |
mkdir -p "$LOG_DIR" | |
# Get the list of pods for the deployment | |
PODS=$(kubectl get pods -l "app=$DEPLOYMENT_NAME" -o jsonpath='{.items[*].metadata.name}') | |
# Loop through each pod and get its logs | |
for POD in $PODS; do | |
LOG_FILE="$LOG_DIR/$POD.log" | |
echo "Getting logs for pod $POD..." | |
kubectl logs "$POD" > "$LOG_FILE" | |
done | |
echo "Finished getting logs for all pods in deployment $DEPLOYMENT_NAME." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment