当前位置:网站首页>Kubernetes practical tips: using ksniff to capture packets
Kubernetes practical tips: using ksniff to capture packets
2022-06-24 15:20:00 【imroc】
This article excerpts from kubernetes Learning notes
summary
Kubernetes How to deal with network problems in the environment ? The traditional way is to log in Pod The node , then Into the container netns, Finally, use the node tcpdump Tools to grab bags . The whole process is complicated , Fortunately, the community has emerged ksniff This gadget , It's a kubectl plug-in unit , We can Kubernetes It's easier and faster to grab bags in the Internet .
This article will show you how to use ksniff This tool is for Pod Carry out the bag .
install
ksniff In general use krew This kubectl Package manager to install :
kubectl krew install sniff
Use wireshark Real time analysis
Grab assignments Pod All NIC packets , Automatically pop up locally installed wireshark And capture it in real time :
kubectl -n test sniff website-7d7d96cdbf-6v4p6
have access to wireshark Real time filter analysis :
Save the capture file
Sometimes in a production environment we may not be able to execute directly locally kubectl, We need to go through the springboard machine , At this time, we can save the captured package as a file , And then copy it to local use wireshark analysis .
Just add one -o
Parameter to specify the path of the saved file :
kubectl -n test sniff website-7d7d96cdbf-6v4p6 -o test.pcap
Privilege mode
ksniff Upload by default tcpdump Binary to target Pod In a container of , Then execute binary to capture the package . But the way to rely on containers is to root User initiated , If not, you can't grab the bag .
We can add one at this time -p
Parameters , Indicates that the Pod A new node is created privileged Of Pod, And then the Pod The container runtime is called (dockerd or containerd etc. ), Start a new one with root Identity activated container, and attach Target Pod Of netns, And then execute container Medium tcpdump Binary to achieve packet capture .
Usage examples :
kubectl -n test sniff website-7d7d96cdbf-6v4p6 -p
View plaintext
If a lot of packet content is plaintext ( such as HTTP), I just want to look at the clear text , You can specify -o -
Print the contents directly to the standard output (stdout):
kubectl -n test sniff website-7d7d96cdbf-6v4p6 -o -
Filter when grabbing
Sometimes there's a lot of data , If you don't filter when you grab , It may be true apiserver Cause a lot of pressure ( The data is transmitted through apiserver), In this case, we'd better specify tcpdump Filter conditions , Block out unwanted data , Avoid data overload .
Add -f
Parameter to specify the filter conditions , Example :
kubectl -n test sniff website-7d7d96cdbf-6v4p6 -f "port 80"
FAQ
wireshark newspaper unknown
When opening the capture file , Report errors pcap: network type 276 unknown or unsupported
:
Usually because wireshark Low version leads to , Just upgrade to the latest version .
Grab the bag times No such file or directory
Use kubectl sniff When caught , Report errors ls: cannot access '/tmp/static-tcpdump': No such file or directory
And then quit :
This is the author in mac Install the latest ksniff v1.6.0 Version problems . The question is obviously a bug,static-tcpdump Binary did not upload to the success of the implementation caused by , Consider three solutions :
- Manual use kubectl cp Copy the binary to the target Pod Re execution kubectl sniff Grab the bag .
- kubectl sniff Appoint
-p
Parameters use privileged mode ( Close test effectively ). - Compile the latest ksniff, Replace the current kubectl-sniff Binary system , This is also the way I use it at present .
边栏推荐
- Esp32 series -- comparison of esp32 series
- 一个简单而功能强大的开发者工具箱Box3.cc
- This website teaches you to imitate more than 100 well-known websites!
- Use tuples
- Domestic payment system and payment background construction
- leetcode 139. Word break word split (medium)
- Six stones Management: garbage dump effect: if you don't manage your work, you will become a garbage dump
- Phpcms upgrade editor method -- simple and effective
- Concurrent writing of maps in golang
- 09_ An efficient memory method
猜你喜欢
Wide measuring range of jishili electrometer
Two way combination of business and technology to build a bank data security management system
Don't underestimate the integral mall. It can play a great role
As a developer, what is the most influential book for you?
CVPR 2022 - Interpretation of selected papers of meituan technical team
Port conflict handling method for tongweb
From pair to unordered_ Map, theory +leetcode topic practice
I have been in the industry for 4 years and have changed jobs twice. I have learned a lot about software testing
Record the range of data that MySQL update will lock
Py's toad: a detailed introduction to toad, its installation and use
随机推荐
Brief discussion on the implementation framework of enterprise power Bi CI /cd
Openinstall joins hands with the book chain to help channel data analysis and create the era of Book Networking
Oracle RAC configuration multipathing
Restoring to an earlier version in CVS
3 ring kill 360 security guard process
Design of vga/lcd display controller system based on FPGA (Part 2)
缓存使用中Redis,Memcached的共性和差异分析
Bert-whitening 向量降维及使用
Step by step introduction to sqlsugar based development framework (9) -- Realizing field permission control with WinForm control
Method after charging the idea plug-in material theme UI
June training (day 24) - segment tree
Detailed explanation of redis data types
The "little giant" specialized in special new products is restarted, and the "enterprise cloud" digital empowerment
US Senate promotes bipartisan gun safety bill
CVPR2022 | 可精簡域適應
IList of PostgreSQL
openinstall携手书链:助力渠道数据分析,共创书联网时代
Ethical considerations
Is it safe to open an account in flush? What preparation is needed
A brief introduction to the lexical analysis of PostgreSQL