Skip to content

Instantly share code, notes, and snippets.

@hexfusion
Forked from ironcladlou/tcpdump-pod
Last active May 5, 2020 17:28
Show Gist options
  • Save hexfusion/d8a743a5867c9d540f5069b51ff36441 to your computer and use it in GitHub Desktop.
Save hexfusion/d8a743a5867c9d540f5069b51ff36441 to your computer and use it in GitHub Desktop.
OpenShift Network Helpers
#!/bin/bash
set -euo pipefail
NAMESPACE=$1
NAME=$2
IMAGE="${IMAGE:-quay.io/dmace/ditm}"
NODE_NAME="$(oc get --namespace $NAMESPACE pods $NAME -o go-template='{{ .spec.nodeName }}')"
CONTAINER_ID_URI="$(oc get --namespace $NAMESPACE pods $NAME -o go-template='{{ (index .status.containerStatuses 0).containerID }}')"
CONTAINER_ID="${CONTAINER_ID_URI:8}"
oc debug --quiet --image $IMAGE nodes/$NODE_NAME --tty=true CONTAINER_ID=$CONTAINER_ID -- /bin/bash -c $'PID=$(chroot /host crictl inspect $CONTAINER_ID -o yaml | grep pid | awk \'{print $2}\'); echo PID=$PID;nsenter -t $PID --net tcpdump -U'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment