当前位置:网站首页>使用 nsenter 进入 netns 抓包
使用 nsenter 进入 netns 抓包
2022-06-10 09:37:00 【衣舞晨风】
背景
我们使用 Kubernetes 时难免发生一些网络问题,往往需要进入容器的网络命名空间 (netns) 中,进行一些网络调试来定位问题,本文介绍如何进入容器的 netns。
获取容器 ID
使用 kubectl 获取 pod 中任意 cotnainer 的 id:
kubectl -n test describe pod debug-685b48bcf5-ggn5d
输出示例片段1 (containerd运行时):
Containers:
debug:
Container ID: containerd://529bbd5c935562a9ba66fc9b9ffa95d486c6324f26d8253d744ffe3dfd728289
输出示例片段2 (dockerd运行时):
Containers:
debug:
Container ID: docker://e64939086488a9302821566b0c1f193b755c805f5ff5370d5ce5e6f154ffc648
获取 PID
拿到 container id 后,我们登录到 pod 所在节点上去获取其主进程 pid。
containerd 运行时使用 crictl 命令获取:
$ crictl inspect 529bbd5c935562a9ba66fc9b9ffa95d486c6324f26d8253d744ffe3dfd728289 | grep -i pid
"pid": 2266462,
"pid": 1
"type": "pid"
此例中 pid 为 2266462
dockerd 运行时使用 docker 命令获取:
$ docker inspect e64939086488a9302821566b0c1f193b755c805f5ff5370d5ce5e6f154ffc648 | grep -i pid
"Pid": 910351,
"PidMode": "",
"PidsLimit": 0,
此例中 pid 为 910351
使用 nsenter 进入容器 netns
在节点上使用 nsenter 进入 pod 的 netns:
nsenter -n --target 910351
调试网络
成功进入容器的 netns,可以使用节点上的网络工具进行调试网络,可以首先使用 ip a 验证下 ip 地址是否为 pod ip:
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
3: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 6a:c6:6f:67:dd:6c brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.18.0.67/26 brd 172.18.0.127 scope global eth0
valid_lft forever preferred_lft forever
原文地址:https://imroc.cc/kubernetes/troubleshooting/skill/network/enter-netns-with-nsenter.html#%E4%BD%BF%E7%94%A8-nsenter-%E8%BF%9B%E5%85%A5-netns-%E6%8A%93%E5%8C%85
边栏推荐
- New retail enterprises build smart marketing system
- 从0开始搭建生物信息学R环境(踩坑记录)
- mmclassification
- Comparison between rancher and kubesphere
- Using requests library to crawl web pages to obtain data
- Example 4 of lambda expression
- Lambda表达式例三
- 基于深度学习的商品推荐系统(Web)
- 【黑马早报】蚂蚁集团暂无启动IPO计划;薇娅老公成立新直播公司;微博CEO质问顺丰;京东将试点餐饮外卖业务;腾讯人才管理体系大调整...
- [fishing artifact] UI library second to second lowcode tool - list part (II) small tool for maintaining JSON
猜你喜欢

收藏 | VLOOKUP函数的这些妙用你都知道吗?

#795 D Max GEQ Sum(单调栈+RMQ)

Why is your next computer a computer? Explore different remote operations

What should we pay attention to when developing, designing and building the reward task source code

mmclassification

P1387 最大正方形(dp)

找工作 笔试
![Pycocotools online installation -- [available]](/img/57/d8d601263b7a8461d0dd0662e6ba32.png)
Pycocotools online installation -- [available]

Data governance in industrial digital transformation

从0开始刷力扣
随机推荐
R语言plotly可视化:plotly可视化互相重叠的归一化直方图(Distplot with Normal Distribution)并在直方图中添加密度曲线kde、在直方图的底部部边缘添加轴须图
Brush force buckle from 0
程序编译基本过程
Solr advanced query application - query by field group
YOLOX: Exceeding YOLO Series in 2021
阅读笔记 PointNet: Deep Learning on Point Sets for 3D Classification and Segmentation
Share the 2022 China supply chain digital upgrading industry research report (PDF attached)
SQL SERVER Always on 监控脚本与一些听到的误解
The R language coin package is applied to permutation tests for independence problems, one-way ANOVA and approximate k-sample permutation tests on the same data set, and comparing whether the mean val
Xiaobai yuesai 49 e Zen (DP)
Huggingface使用过程中遇到的问题
Lambda ellipsis rule
jqGrid表格部分处理方法:
Pycocotools online installation -- [available]
MONGOREPLAY 的“坑”
[dark horse morning post] ant group has no IPO plan yet; Weiya's husband set up a new live broadcasting company; CEO of Weibo questioned SF; JD will pilot the catering takeout business; Tencent's tale
pycocotools在线安装--【可用】
Data governance in industrial digital transformation
从0开始搭建生物信息学R环境(踩坑记录)
How about the course system of PHP