Add kubernetes functions

One for dump all logs related to a deploy and the other to get the pods
of a deployment. They can be used together.
This commit is contained in:
drymer 2018-07-02 22:39:12 +02:00
parent f7d3e64941
commit 823ca426ed
1 changed files with 31 additions and 0 deletions

View File

@ -280,3 +280,34 @@ function warn_me (){
# -v /var/run/docker.sock:/var/run/docker.sock \
# -v `pwd`/config:/home/docker/.ssh/config ansible:2.5 "$@"
# }
function kube_dump_logs(){
local deploy="$1"
local time="$2"
if [[ -z "$deploy" ]]
then
echo "You must pass a kubernetes deployment as an argument."
return 1
fi
if [[ -z "$time" ]]
then
time=1h
fi
mkdir -p "$deploy"
for pod in $(ku get pods | grep "$deploy" | awk '{print $1}')
do
ku logs "$pod" --since="$time" > "$deploy"/"$pod"
done
echo "Dumped $deploy logs."
}
function kube_get_deploy_pods(){
local deploy="$1"
if [[ -z "$deploy" ]]
then
echo "You must pass a kubernetes deployment as an argument."
return 1
fi
ku get pods | grep "$deploy" | awk '{print $1}'
}