Skip to content

Instantly share code, notes, and snippets.

@j0ju
Last active January 6, 2026 14:34
Show Gist options
  • Select an option

  • Save j0ju/811b6c616525b196ebde139e283d170c to your computer and use it in GitHub Desktop.

Select an option

Save j0ju/811b6c616525b196ebde139e283d170c to your computer and use it in GitHub Desktop.
Very experimental and hacky IPerf2/3 deployment for k8s with experimental priviledged init containers to change network config if needed
---
apiVersion: v1
kind: Service
metadata:
name: iperf
spec:
selector:
app: iperf
ports:
- name: iperf2-tcp
protocol: TCP
port: 5001
targetPort: 5001
- name: iperf2-udp
protocol: UDP
port: 5001
targetPort: 5001
- name: iperf3-tcp
protocol: TCP
port: 5201
targetPort: 5201
- name: iperf3-udp
protocol: UDP
port: 5201
targetPort: 5201
externalIPs:
- "2001:db8::5001"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: iperf
labels:
app: iperf
spec:
replicas: 1
selector:
matchLabels:
app: iperf
template:
metadata:
labels:
app: iperf
spec:
initContainers:
- name: init
image: busybox
command: [ "/bin/sh", "-c" ]
args:
- |
set -eu
set -x
#
mkdir -p /tmp
mount -t tmpfs tmpfs /tmp
#
mount
#env | sort
ip a | grep ^[0-9]
# test if a network interaface local namespace does not leak on exit
ip link add dummy0 type dummy
#
nsenter -n/pid1.namespaces/net -- ip a | grep ^[0-9]
ip a | grep ^[0-9]
ip -4 r
ip -6 r
ls -l /proc/1/ns/* /pid1.namespaces/* || :
securityContext:
privileged: true
runAsUser: 0
volumeMounts:
- name: pid1-ns
mountPath: /pid1.namespaces
containers:
- name: iperf
image: debian:trixie
securityContext:
privileged: false
command: [ "/bin/sh", "-c" ]
args:
- |
set -eu
set -x
#
rm -f /etc/apt/apt.conf.d/docker-clean
apt-get update
apt-get install -y busybox iproute2 iperf iperf3 # vim-nox mc busybox procps psmisc
#
mkdir -p /tmp
mount -t tmpfs tmpfs /tmp || :
#
# this will fail, we have not privileges
ip link add dummy0 type dummy
#
mount
env | sort
ip a
ip -4 r
ip -6 r
#
iperf -V -s -p 5001 &
iperf -V -s -p 5001 -u &
iperf3 -s &
#
sleep 86400
env:
- name: DEBIAN_FRONTEND
value: noninteractive
ports:
- name: iperf2-tcp
containerPort: 5001
protocol: TCP
- name: iperf2-udp
containerPort: 5001
protocol: UDP
- name: iperf3-tcp
containerPort: 5201
protocol: TCP
- name: iperf3-udp
containerPort: 5201
protocol: UDP
volumeMounts:
- name: var-cache-apt-archives
mountPath: /var/cache/apt/archives
volumes:
- name: var-cache-apt-archives
hostPath:
path: /var/cache/apt/archives
type: Directory
- name: pid1-ns
hostPath:
path: /proc/1/ns
type: Directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment