返回排行榜

eldadru/ksniff

Go

Kubectl plugin to ease sniffing on kubernetes pods using tcpdump and wireshark

kubectl-pluginskubectldebuggingsniffingwiresharkkubernetes
Star 增长趋势
Star
3.5k
Forks
212
周增长
Issues
49
1k2k3k
2023年1月2024年3月2025年5月2026年7月
制品库Go Modulesgo get github.com/eldadru/ksniff
README

ksniff

Build Status

A kubectl plugin that utilize tcpdump and Wireshark to start a remote capture on any pod in your Kubernetes cluster.

You get the full power of Wireshark with minimal impact on your running pods.

Intro

When working with micro-services, many times it's very helpful to get a capture of the network activity between your micro-service and it's dependencies.

ksniff use kubectl to upload a statically compiled tcpdump binary to your pod and redirecting it's output to your local Wireshark for smooth network debugging experience.

Demo

Demo!

Production Readiness

Ksniff isn't production ready yet, running ksniff for production workloads isn't recommended at this point.

Installation

Installation via krew (https://github.com/GoogleContainerTools/krew)

kubectl krew install sniff

For manual installation, download the latest release package, unzip it and use the attached makefile:

unzip ksniff.zip
make install

Wireshark

If you are using Wireshark with ksniff you must use at least version 3.4.0. Using older versions may result in issues reading captures (see Known Issues below).

Build

Requirements:

  1. libpcap-dev: for tcpdump compilation (Ubuntu: sudo apt-get install libpcap-dev)
  2. go 1.11 or newer

Compiling:

linux:      make linux
windows:    make windows
mac:        make darwin

To compile a static tcpdump binary:

make static-tcpdump

Usage

kubectl < 1.12:
kubectl plugin sniff <POD_NAME> [-n <NAMESPACE_NAME>] [-c <CONTAINER_NAME>] [-i <INTERFACE_NAME>] [-f <CAPTURE_FILTER>] [-o OUTPUT_FILE] [-l LOCAL_TCPDUMP_FILE] [-r REMOTE_TCPDUMP_FILE]

kubectl >= 1.12:
kubectl sniff <POD_NAME> [-n <NAMESPACE_NAME>] [-c <CONTAINER_NAME>] [-i <INTERFACE_NAME>] [-f <CAPTURE_FILTER>] [-o OUTPUT_FILE] [-l LOCAL_TCPDUMP_FILE] [-r REMOTE_TCPDUMP_FILE]

POD_NAME: Required. the name of the kubernetes pod to start capture it's traffic.
NAMESPACE_NAME: Optional. Namespace name. used to specify the target namespace to operate on.
CONTAINER_NAME: Optional. If omitted, the first container in the pod will be chosen.
INTERFACE_NAME: Optional. Pod Interface to capture from. If omitted, all Pod interfaces will be captured.
CAPTURE_FILTER: Optional. specify a specific tcpdump capture filter. If omitted no filter will be used.
OUTPUT_FILE: Optional. if specified, ksniff will redirect tcpdump output to local file instead of wireshark. Use '-' for stdout.
LOCAL_TCPDUMP_FILE: Optional. if specified, ksniff will use this path as the local path of the static tcpdump binary.
REMOTE_TCPDUMP_FILE: Optional. if specified, ksniff will use the specified path as the remote path to upload static tcpdump to.

Air gapped environments

Use --image and --tcpdump-image flags (or KUBECTL_PLUGINS_LOCAL_FLAG_IMAGE and KUBECTL_PLUGINS_LOCAL_FLAG_TCPDUMP_IMAGE environment variables) to override the default container images and use your own e.g (docker):

kubectl plugin sniff <POD_NAME> [-n <NAMESPACE_NAME>] [-c <CONTAINER_NAME>] --image <PRIVATE_REPO>/docker --tcpdump-image <PRIVATE_REPO>/tcpdump

Non-Privileged and Scratch Pods

To reduce attack surface and have small and lean containers, many production-ready containers runs as non-privileged user or even as a scratch container.

To support those containers as well, ksniff now ships with the "-p" (privileged) mode. When executed with the -p flag, ksniff will create a new pod on the remote kubernetes cluster that will have access to the node docker daemon.

ksniff will than use that pod to execute a container attached to the target container network namespace and perform the actual network capture.

Piping output to stdout

By default ksniff will attempt to start a local instance of the Wireshark GUI. You can integrate with other tools using the -o - flag to pipe packet cap data to stdout.

Example using tshark:

kubectl sniff pod-name -f "port 80" -o - | tshark -r -

Contribution

More than welcome! please don't hesitate to open bugs, questions, pull requests

Future Work

  1. Instead of uploading static tcpdump, use the future support of "kubectl debug" feature (https://github.com/kubernetes/community/pull/649) which should be a much cleaner solution.

Known Issues

Wireshark and TShark cannot read pcap

Issues 100 and 98

Wireshark may show UNKNOWN in Protocol column. TShark may report the following in output:

tshark: The standard input contains record data that TShark doesn't support.
(pcap: network type 276 unknown or unsupported)

This issue happens when using an old version of Wireshark or TShark to read the pcap created by ksniff. Upgrade Wireshark or TShark to resolve this issue. Ubuntu LTS versions may have this problem with stock package versions but using the Wireshark PPA will help.

相关仓库
ahmetb/kubectx

Faster way to switch between clusters and namespaces in kubectl

GoGo ModulesApache License 2.0kuberneteskubectl
kubectx.dev
19.9k1.4k
kubernetes-sigs/krew

📦 Find and install kubectl plugins

GoGo ModulesApache License 2.0kubectlkubectl-plugins
krew.sigs.k8s.io
7k410
ahmetb/kubectl-tree

kubectl plugin to browse Kubernetes object hierarchies as a tree 🎄 (star the repo if you are using)

GoGo ModulesApache License 2.0kubectl-pluginkubectl-plugins
3.4k136
int128/kubelogin

kubectl plugin for Kubernetes OpenID Connect authentication (kubectl oidc-login)

GoGo ModulesApache License 2.0kuberneteskubectl
2.3k239
aylei/kubectl-debug

This repository is no longer maintained, please checkout https://github.com/JamesTGrant/kubectl-debug.

GoGo ModulesApache License 2.0kubectlkubectl-plugins
2.3k302
iovisor/kubectl-trace

Schedule bpftrace programs on your kubernetes cluster using the kubectl

GoGo ModulesMIT Licensekubectlkubernetes-cluster
2.2k175
kubepug/kubepug

Kubernetes PreUpGrade (Checker)

GoGo ModulesApache License 2.0kuberneteskubectl-plugins
kubepug.xyz
1.8k81
kvaps/kubectl-node-shell

Exec into node via kubectl

ShellApache License 2.0kubectlkubectl-plugin
1.8k196
kubecolor/kubecolor

Colorize your kubectl output

GoGo ModulesMIT Licensebashcli
kubecolor.github.io
1.4k44
corneliusweig/rakkess

Review Access - kubectl plugin to show an access matrix for k8s server resources

GoGo ModulesApache License 2.0kubectl-pluginkubernetes
1.4k60
sozercan/kubectl-ai

✨ Kubectl plugin to create manifests with LLMs

GoGo ModulesMIT Licensekubernetesopenai
1.2k88
ishantanu/awesome-kubectl-plugins

Curated list of kubectl plugins

Creative Commons Zero v1.0 Universalkubectl-pluginsawesome-list
1k70