-
Notifications
You must be signed in to change notification settings - Fork 27
/
dspcap-start
executable file
·59 lines (57 loc) · 1.32 KB
/
dspcap-start
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
#!/bin/bash
set -e
set -o pipefail
STARTTIME=$(date -u +%Y-%m-%dT%H:%M)
PIDFILE=/var/run/dspcap.pid
NAMESPACE=default
IMAGE=alpine:3.15
# IMAGE=mcr.microsoft.com/dotnet/runtime-deps:6.0
TCPDUMP_ARGS="-i any -s 100 -C 100"
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: dspcap
namespace: $NAMESPACE
spec:
selector:
matchLabels:
app: dspcap
template:
metadata:
labels:
app: dspcap
spec:
hostPID: true
hostNetwork: true
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
containers:
- name: tcpdump
command:
- nsenter
- --mount=/proc/1/ns/mnt
- --
- bash
- -xc
- |
mkdir -p /tmp/dspcap
chmod 777 /tmp/dspcap
echo "starting pcap"
tcpdump $TCPDUMP_ARGS -w "/tmp/dspcap/$STARTTIME.\$(hostname).pcap" &
echo \$! >$PIDFILE
wait
rm $PIDFILE
echo "sleeping forever"
sleep infinity
image: $IMAGE
resources:
requests:
cpu: 50m
memory: 50M
securityContext:
privileged: true
EOF
kubectl rollout status daemonset/dspcap -n $NAMESPACE
echo "Capture started. Use dspcap-stop to stop capture and collect outcome."