Capture the packets from a pod on the Kubernetes cluster

This article discusses how to take a traffic capture at a pod of an Azure Kubernetes Service (AKS) cluster, and view the capture on your local computer.

Prerequisite


In this article, we will introduce Ksniff as a Kubernetes-integrated packet sniffer, developed by Eldad Rudich.

Below software are required to be installed

Once you have installed ksniff and have a pod running, it’s time to capture some network traffic. Running kubectl sniff $POD_NAME will begin a packet capture,

# command to get the pod name
kubectl get pod -n <namespace>
# command to run ksniff
kubectl sniff <POD_Name>

Running the above command will open up the Wireshark and will start to show the packets.

Packet captures can become very messy, especially for pods that run complex or highly utilized workloads. tcpdump filters are a key part of making complex packet captures easier, and ksniff supports them right out of the box:

kubectl sniff nginx -f "tcp port 80"

References

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

en_USEnglish