-
Notifications
You must be signed in to change notification settings - Fork 0
/
pod-starter.py
40 lines (34 loc) · 1 KB
/
pod-starter.py
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
import datetime
from kubernetes import client, config
config.load_kube_config()
# Generate a unique pod name
base_pod_name = "stress-ng-pod"
unique_suffix = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
pod_name = f"{base_pod_name}-{unique_suffix}"
pod_manifest = {
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": pod_name
},
"spec": {
"containers": [{
"name": "stress-ng-container",
"image": "polinux/stress-ng:latest",
"args": [
"stress-ng",
"--io", "1",
"--vm", "1",
"--vm-bytes", "1G",
"--timeout", "1m"
]
}]
}
}
api_instance = client.CoreV1Api()
namespace = 'default'
try:
api_response = api_instance.create_namespaced_pod(namespace, pod_manifest)
print(f"Pod {pod_name} created. Status: {api_response.status}")
except client.ApiException as e:
print(f"Exception when calling CoreV1Api->create_namespaced_pod: {e}")