Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Created August 4, 2021 14:00
Show Gist options
  • Save tuxfight3r/082ddafb892e3bbf00251b48782413a7 to your computer and use it in GitHub Desktop.
Save tuxfight3r/082ddafb892e3bbf00251b48782413a7 to your computer and use it in GitHub Desktop.
kube-liveness-test.sh
#Simple script to test all the pods liveness/readiness
#creates portforward and curls the endpoint for status
#clears the portforward at the end of the script
#uses bash v3 based implementation.
#Test only the pods which are up.
#!/bin/bash
aggregate_feed="tfeed"
aggregates=( "app1:7101"
"app2:7102"
"app3:7103"
)
k="kubectl"
for item in "${aggregates[@]}"; do
key=${item%%:*}
port=${item#*:}
name="test-${key}-${aggregate_feed}-0"
echo -e "\n\n$name -> $port"
pod_name=$($k get pods |grep Running|awk "/$key-${aggregate_feed}/{print $1}"|head -1|cut -d " " -f1)
if [[ ! -z ${pod_name} ]]; then
echo "POD: $pod_name"
$k port-forward ${name} ${port}:${port} & &>/dev/null
sleep 3
curl http://localhost:${port}/${key}-${aggregate_feed}/health/readiness
else
echo "${name}: Pod Not Found"
fi
done
echo ""
killall kubectl 2>&1 > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment