2021-09-29 06:11:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
ns_name=$1
|
|
|
|
prefix_name=$2
|
|
|
|
array=($(kubectl get pod -n ${ns_name}|grep ${prefix_name}|awk '{print $1}'))
|
2021-09-16 10:53:49 +00:00
|
|
|
echo ${array[@]}
|
|
|
|
log_dir="k8s_logs"
|
2021-09-29 06:11:59 +00:00
|
|
|
if [ ! -d $log_dir ];
|
|
|
|
then
|
|
|
|
mkdir $log_dir
|
|
|
|
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-09-29 06:11:59 +00:00
|
|
|
kubectl logs $pod -n ${ns_name} > ./$log_dir/$pod.log
|
2021-09-16 10:53:49 +00:00
|
|
|
done
|
2021-09-23 07:08:00 +00:00
|
|
|
echo "export logs done"
|