2021-09-29 06:11:59 +00:00
|
|
|
#!/bin/bash
|
2021-11-10 11:24:18 +00:00
|
|
|
|
|
|
|
# Exit immediately for non zero status
|
2021-09-29 06:11:59 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
ns_name=$1
|
|
|
|
prefix_name=$2
|
2021-11-06 11:42:58 +00:00
|
|
|
log_dir=${3:-"k8s_logs"}
|
2021-09-29 06:11:59 +00:00
|
|
|
array=($(kubectl get pod -n ${ns_name}|grep ${prefix_name}|awk '{print $1}'))
|
2021-09-16 10:53:49 +00:00
|
|
|
echo ${array[@]}
|
2021-09-29 06:11:59 +00:00
|
|
|
if [ ! -d $log_dir ];
|
|
|
|
then
|
2021-11-05 01:11:43 +00:00
|
|
|
mkdir -p $log_dir
|
2021-09-29 06:11:59 +00:00
|
|
|
fi
|
2021-09-16 10:53:49 +00:00
|
|
|
echo "export logs start"
|
|
|
|
for pod in ${array[*]}
|
|
|
|
do
|
|
|
|
echo "export logs for pod $pod "
|
2021-10-26 13:12:20 +00:00
|
|
|
kubectl logs $pod -n ${ns_name} > ./$log_dir/$pod.log 2>&1
|
2021-09-16 10:53:49 +00:00
|
|
|
done
|
2021-09-23 07:08:00 +00:00
|
|
|
echo "export logs done"
|