-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path4_2_SimulatePodFailure.sh
executable file
·73 lines (59 loc) · 2.55 KB
/
4_2_SimulatePodFailure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
#####################################################################
# Script name: Simulate pod failure
# Description: This script will delete the existing SQL Server pod
# Author: Carlos Robles
# Email: [email protected]
#####################################################################
# Variables
k8s_cluster=endurance-admin;
namespace=plex-sql;
# Setting kubectl context to desired cluster
echo -e "Setting kubectl context to Docker desktop\n"
kubectl config use-context $k8s_cluster
kubectl config set-context --current --namespace=$namespace
echo -e "=============================================="
echo -e " Simulating failure"
echo -e "=============================================="
echo -e " Start time:" `date +"%T"`
echo -e "=============================================="
# Checking pod status
echo -e "\nGetting status of curent pods:"
echo -e "**********************************************\n"
kubectl get pods -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName
# Getting pod name
pod=`kubectl get pods -l app=sql-plex --no-headers -o custom-columns=":metadata.name"`
# Deleting pods
echo -e "\n Deleting pods / Simulating pod failure"
echo -e "********************************************** \n"
kubectl delete pod $pod --grace-period=0 --force
# Setting star time for timer
start_time="$(date -u +%s)"
# Wait for pod to be deleted
#sleep 10
status=0
while [ $status -le 0 ]
do
echo -e "\nWaiting for new pod ... "
status=`kubectl get pods --field-selector=status.phase=Running | grep sql-plex | wc -l`
sleep 2
done
# Setting end time for timer
end_time="$(date -u +%s)"
# Get pods
echo -e "\nGetting status of new pod:\n"
echo -e "**********************************************\n"
sleep 4
kubectl get pods -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName
# Get latest pod status
echo -e "\nChecking SQL Server logs from latest pod:"
echo -e "**********************************************\n"
new_pod=`kubectl get pods -l app=sql-plex --no-headers -o custom-columns=":metadata.name"`
kubectl logs $new_pod
# Calculating outage
elapsed="$(($end_time-$start_time))"
echo -e "=============================================="
echo -e " Script finished "
echo -e " Stop time:" `date +"%T"`
echo -e " Outage in seconds: $elapsed"
echo -e "=============================================="