-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoom-kill.sh
More file actions
73 lines (67 loc) · 1.82 KB
/
oom-kill.sh
File metadata and controls
73 lines (67 loc) · 1.82 KB
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
# Variables
NAMESPACE="interdependent-services"
SERVICE_A_DEPLOYMENT="service-a"
SERVICE_B_DEPLOYMENT="service-b"
# Step 1: Create a namespace for the workload
kubectl create namespace $NAMESPACE || echo "Namespace $NAMESPACE already exists"
# Step 2: Deploy Service B (Backend) with stress-ng to induce OOMKill
cat <<EOF | kubectl apply -n $NAMESPACE -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: $SERVICE_B_DEPLOYMENT
spec:
replicas: 1
selector:
matchLabels:
app: service-b
template:
metadata:
labels:
app: service-b
spec:
containers:
- name: service-b
image: polinux/stress-ng # Use stress-ng to stress memory
command: ['stress-ng', '--vm', '1', '--vm-bytes', '120M', '--timeout', '600s'] # Allocate 120MB of memory
resources:
limits:
memory: "128Mi" # Set memory limit to force OOMKill
cpu: "500m"
requests:
memory: "64Mi"
cpu: "250m"
ports:
- containerPort: 80
EOF
# Step 3: Deploy Service A (Frontend making requests to Service B)
cat <<EOF | kubectl apply -n $NAMESPACE -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: $SERVICE_A_DEPLOYMENT
spec:
replicas: 1
selector:
matchLabels:
app: service-a
template:
metadata:
labels:
app: service-a
spec:
containers:
- name: service-a
image: busybox
command: ['sh', '-c']
args:
- |
while true; do
wget -qO- http://service-b:80 || echo "Failed to reach Service B";
sleep 5;
done;
EOF
echo "Workload with interdependent services deployed."
# Step 4: Monitor the pod status
echo "Use 'kubectl get pods -n $NAMESPACE' to monitor the pod status and watch for the OOMKilled event."