Skip to content

Commit

Permalink
Collect logging for exited containers (#70)
Browse files Browse the repository at this point in the history
For any containers with non-0 restart counts, collect logging for exited
containers using `kubectl logs ... --previous`.
  • Loading branch information
adriansuarez authored Oct 3, 2024
1 parent 454c6f9 commit 0809af3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions deploy/k8s/logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
if [ -d "$OUTPUT_DIR" ]; then
mkdir -p "$OUTPUT_DIR/cluster-info"
kubectl cluster-info dump -A --output-directory="$OUTPUT_DIR/cluster-info"

# For any containers that have restarted, collect the exited container output
(
kubectl get pod -A -o jsonpath="{range .items[*]}{.metadata.namespace}{' '}{.metadata.name}{' '}{.status.containerStatuses[?(.restartCount > 0)].name}{'\n'}{end}"
) | while read ns pod containers; do
for container in $containers; do
kubectl logs -n "$ns" "$pod" -c "$container" --previous > "$OUTPUT_DIR/cluster-info/$ns/$pod/logs-$container-previous.txt"
done
done
else
kubectl cluster-info dump -A
fi

0 comments on commit 0809af3

Please sign in to comment.