-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathkubectl-windows-debug
executable file
·105 lines (94 loc) · 2.47 KB
/
kubectl-windows-debug
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# default image
image="ghcr.io/jsturtevant/windows-debug:v1.0.0"
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
echo "Windows node access via kubectl"
echo " "
echo "kubectl windows-debug <windows-node-name> [options]"
echo " "
echo "options:"
echo "-h, --help Show brief help"
echo "-i, --image use custom image"
echo "-r, --requests set resource requests for the debug container (e.g., CPU and memory)"
echo "-l, --limits set resource limit for the debug container (e.g., maximum CPU and memory)"
exit 0
;;
-i | --image)
image="$2"
shift # past argument
shift # past value
;;
-r|--requests)
requests="$2"
shift # past argument
shift # past value
;;
-l|--limits)
limits="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1")
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
nodename="$1"
echo "Running on node '$nodename' with image '$image'"
echo "Running with requests '$requests' and limits '$limits'"
if [[ -n "${requests}" ]]; then
request_json=$(echo $requests | awk 'BEGIN{FS="[=,]"}{printf "{\"%s\":\"%s\",\"%s\":\"%s\"}", $1, $2, $3, $4}')
else
request_json="{}"
fi
if [[ -n "${limits}" ]]; then
limit_json=$(echo $limits | awk 'BEGIN{FS="[=,]"}{printf "{\"%s\":\"%s\",\"%s\":\"%s\"}", $1, $2, $3, $4}')
else
limit_json="{}"
fi
# sometime ns default is empty from this command so default if it is
namespace=$(kubectl config view --minify --output 'jsonpath={..namespace}')
if [ -z "$namespace" ]; then namespace="default"; fi;
podname=windows-debug-${RANDOM}
overrides=$(cat <<-JSON
{
"spec": {
"containers": [
{
"name": "$podname",
"image": "$image",
"resources": {
"requests": $request_json,
"limits": $limit_json
}
}
],
"nodeName": "$nodename",
"nodeSelector": {
"kubernetes.io/os": "windows"
},
"hostNetwork": true,
"securityContext": {
"windowsOptions": {
"hostProcess": true,
"runAsUserName": "NT AUTHORITY\\\\SYSTEM"
}
}
}
}
JSON
)
kubectl run $podname \
-it --rm -n $namespace --image $image \
--image-pull-policy=Always \
--restart=Never --overrides "$overrides" \
--override-type=strategic \
--pod-running-timeout=15m0s \
--command -- powershell