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