2025-01-02 10:46:09 +08:00

34 lines
1.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

K8S的POD时常出现网络问题而在制作容器镜像时往往没有安装网络排障工具也没有配置sidecar容器排障特别困难。为了解决这个问题我们可以通过nsenter在node上抓取pod 的数据包
## 获取pod所在的node位置以及容器ID
```
kubectl describe pod pod-name -n namespace-name
#Node: 192.168.1.21/192.168.1.21 //确认pod 在21这台服务器上
#Containers:
# Container ID: containerd://d885d05d37342a24ebca5d791f803e4ae8698f654a94b0e4f1808e65cb4c0ef1 //确认容器ID
```
## 获取容器的PID
我们登录21这台服务器去获取主进程的PID
```
crictl inspect d885d05d37342a24ebca5d791f803e4ae8698f654a94b0e4f1808e65cb4c0ef1
# "info": {
# "pid": 64774,
```
## 使用 nsenter 进入容器 netns
在节点上使用 nsenter 进入 pod 的 netns:
```
nsenter -n --target 64774
```
查看IP地址 是否为POD IP地址
```
ip a
```
此时即可通过tcpdump抓包了抓的包就是pod内的数据包。
```
exit //通过此命令退出nsenter
```