Giter Site home page Giter Site logo

ktcpdump's Introduction

ktcpdump

A simple wrapper script to run tcpdump nicely on Kubernetes.

This tool will deploy a DaemonSet in the Kubernetes cluster using kubectl and run tcpdump on host network to capture network traffic.

The DaemonSet is based on praqma/network-multitool Docker image.

!! Important Note: Please use this tool in production by CAUTION !!

What's new

The script extends the tcpdump filter expressions by translating them to pcap-filter format.

  1. [namespace/]pod/pod_name
  2. [namespace/]deploy/deployment_name
  3. [namespace/]ds/daemonset_name

Some default behaviors:

  • If namespace is not specified, current namespace will be used.
  • The script runs tcpdump with some options by default, so it will not exhaust the disk space and create unnecessary DNS requests by accident.

Prerequisites

Install from source

Check out the ktcpdump repository. And then, run the provided install.sh command with the location to the prefix in which you want to install ktcpdump. By default, it installs the tool into /usr/local.

git clone https://[email protected]:PandaXass/ktcpdump.git
cd ktcpdump
sudo ./install.sh

Uninstall

# Remove the installed directory
sudo rm -r /usr/local/ktcpdump
# Remove the symlink
rm /usr/local/bin/ktcpdump

Usage examples

Some examples about how to use the tool.

# Show usage information
ktcpdump help
# Create ktcpdump DaemonSet
ktcpdump create
# Show versions (need DeamonSet to be created first)
ktcpdump version
# Capture traffic on all Kubenetes hosts
ktcpdump run
# Capture traffic on Pod and write to the file
ktcpdump run pod <pod_name> -w ktcpdump.pcap
# Capture traffic from the source Pod to the dest Pod with verbose mode
ktcpdump run -v src pod <pod1_name> and dst pod <pod2_name>
# Capture RST and FIN packets between Pod and Deployment in different Namespaces
ktcpdump run <ns1_name>/pod/<pod_name> and <ns2_name>/deploy/<deploy_name> and 'tcp[tcpflags] & (tcp-rst|tcp-fin) != 0'
# Capture all TCP packets on destination Deployment port 8080
./ktcpdump run -v dst <ns_name>/deploy/<deploy_name> and 'tcp port 8080'
# Rerun previous "run" command
ktcpdump rerun
# Show ktcpdump status
ktcpdump status
# Show ktcpdump DaemonSet logs
ktcpdump logs
# Copy ktcpdump.pcap file from DaemonSet Pods to local folder
ktcpdump cp ktcpdump.pcap
# Merge all capture files
mergecap -w outfile.pcap *.pcap
# Delete the DaemonSet
ktcpdump purge

Known Limitations

  • Running this tool could potentially generate a long tcpdump command. And the total size of the command line argument is limited to getconf ARG_MAX.
  • The tool retrieves the pods IPs in the beginning of each run. In Kubenetes, the pods (together with IPs) can be created and terminated dynamically. However those changes will not be reflected in the output. In other words, this tool might miss capturing some network packets due to pod changes.

ktcpdump's People

Contributors

pandaxass avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.