我希望有一个指向Kubernetes集群中pod的NodePort服务的节点端口(如30034)的tcpdump。此节点端口服务映射在路径下的入口资源内。当我使用入口内配置的主机点击入口时,我从目标pod得到响应,但tcpdump没有跟踪任何东西。(入口--
我尝试过:sudo tcpdump-I any port 30034-w tcp dump。但它并没有捕获任何东西。
你能在这里提出建议吗。当流量通过入口控制器时,tcpdump无法捕获任何内容的原因是什么。但是,如果我直接命中节点https://node-ip:30034:/service; 我收到tcpdump。
谢谢。
大多数入口控制器实际上绕过库贝代理层并直接使用endpointIP,因此这似乎可能是相关的。通常,由于过多的虚拟网络和时髦的iptables规则,很难在容器系统中获取数据包跟踪。
在Kubernetes中,TCPdump的有效性有点棘手,需要您为pod创建一个侧车。你所面临的实际上是预期的行为。
运行好的旧东西,如TCPump或ngrep不会产生太多有趣的信息,因为您直接链接到桥接网络或在默认场景中覆盖。
好消息是,您可以将TCPump容器链接到主机网络,甚至更好地链接到容器网络堆栈。来源:如何在Docker中有效地TCPump
问题是您有两个入口点,一个是nodeIP:NodePort,另一个是ClusterIP:Port。两者都指向kubernetes iptables上设置的endpoint的同一组随机化规则。
一旦这种情况发生在任何节点上,就很难将tcpdump配置为只在一个点上捕获所有感兴趣的流量。
我所知道的用于此类分析的最佳工具是Istio,但它主要适用于HTTP流量。
考虑到这一点,最好的解决方案是为服务后面的每个pod使用tcpdumper侧车。
让我们通过一个例子来说明如何实现这一点
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: web-app
spec:
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web-app
image: nginx
imagePullPolicy: Always
ports:
- containerPort: 80
protocol: TCP
- name: tcpdumper
image: docker.io/dockersec/tcpdump
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: web-svc
namespace: default
spec:
ports:
- nodePort: 30002
port: 80
protocol: TCP
targetPort: 80
selector:
app: web
type: NodePort
在这份清单上,我们可以注意到三件重要的事情。我们有一个nginx容器和一个tcpdumper容器作为侧车,我们有一个定义为NodePort的服务。
要访问我们的sidecar,您必须运行以下命令:
$ kubectl attach -it web-app-db7f7c59-d4xm6 -c tcpdumper
例子:
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 13d
web-svc NodePort 10.108.142.180 <none> 80:30002/TCP 9d
$ curl localhost:30002
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
$ kubectl attach -it web-app-db7f7c59-d4xm6 -c tcpdumper
Unable to use a TTY - container tcpdumper did not allocate one
If you don't see a command prompt, try pressing enter.
> web-app-db7f7c59-d4xm6.80: Flags [P.], seq 1:78, ack 1, win 222, options [nop,nop,TS val 300957902 ecr 300958061], length 77: HTTP: GET / HTTP/1.1
12:03:16.884512 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.1336: Flags [.], ack 78, win 217, options [nop,nop,TS val 300958061 ecr 300957902], length 0
12:03:16.884651 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.1336: Flags [P.], seq 1:240, ack 78, win 217, options [nop,nop,TS val 300958061 ecr 300957902], length 239: HTTP: HTTP/1.1 200 OK
12:03:16.884705 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.1336: Flags [P.], seq 240:852, ack 78, win 217, options [nop,nop,TS val 300958061 ecr 300957902], length 612: HTTP
12:03:16.884743 IP 192.168.250.64.1336 > web-app-db7f7c59-d4xm6.80: Flags [.], ack 240, win 231, options [nop,nop,TS val 300957902 ecr 300958061], length 0
12:03:16.884785 IP 192.168.250.64.1336 > web-app-db7f7c59-d4xm6.80: Flags [.], ack 852, win 240, options [nop,nop,TS val 300957902 ecr 300958061], length 0
12:03:16.889312 IP 192.168.250.64.1336 > web-app-db7f7c59-d4xm6.80: Flags [F.], seq 78, ack 852, win 240, options [nop,nop,TS val 300957903 ecr 300958061], length 0
12:03:16.889351 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.1336: Flags [F.], seq 852, ack 79, win 217, options [nop,nop,TS val 300958062 ecr 300957903], length 0
12:03:16.889535 IP 192.168.250.64.1336 > web-app-db7f7c59-d4xm6.80: Flags [.], ack 853, win 240, options [nop,nop,TS val 300957903 ecr 300958062], length 0
12:08:10.336319 IP6 fe80::ecee:eeff:feee:eeee > ff02::2: ICMP6, router solicitation, length 16
12:15:47.717966 IP 192.168.250.64.2856 > web-app-db7f7c59-d4xm6.80: Flags [S], seq 3314747302, win 28400, options [mss 1420,sackOK,TS val 301145611 ecr 0,nop,wscale 7], length 0
12:15:47.717993 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.2856: Flags [S.], seq 2539474977, ack 3314747303, win 27760, options [mss 1400,sackOK,TS val 301145769 ecr 301145611,nop,wscale 7], length 0
12:15:47.718162 IP 192.168.250.64.2856 > web-app-db7f7c59-d4xm6.80: Flags [.], ack 1, win 222, options [nop,nop,TS val 301145611 ecr 301145769], length 0
12:15:47.718164 IP 192.168.250.64.2856 > web-app-db7f7c59-d4xm6.80: Flags [P.], seq 1:78, ack 1, win 222, options [nop,nop,TS val 301145611 ecr 301145769], length 77: HTTP: GET / HTTP/1.1
12:15:47.718191 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.2856: Flags [.], ack 78, win 217, options [nop,nop,TS val 301145769 ecr 301145611], length 0
12:15:47.718339 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.2856: Flags [P.], seq 1:240, ack 78, win 217, options [nop,nop,TS val 301145769 ecr 301145611], length 239: HTTP: HTTP/1.1 200 OK
12:15:47.718403 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.2856: Flags [P.], seq 240:852, ack 78, win 217, options [nop,nop,TS val 301145769 ecr 301145611], length 612: HTTP
12:15:47.718451 IP 192.168.250.64.2856 > web-app-db7f7c59-d4xm6.80: Flags [.], ack 240, win 231, options [nop,nop,TS val 301145611 ecr 301145769], length 0
12:15:47.718489 IP 192.168.250.64.2856 > web-app-db7f7c59-d4xm6.80: Flags [.], ack 852, win 240, options [nop,nop,TS val 301145611 ecr 301145769], length 0
12:15:47.723049 IP 192.168.250.64.2856 > web-app-db7f7c59-d4xm6.80: Flags [F.], seq 78, ack 852, win 240, options [nop,nop,TS val 301145612 ecr 301145769], length 0
12:15:47.723093 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.2856: Flags [F.], seq 852, ack 79, win 217, options [nop,nop,TS val 301145770 ecr 301145612], length 0
12:15:47.723243 IP 192.168.250.64.2856 > web-app-db7f7c59-d4xm6.80: Flags [.], ack 853, win 240, options [nop,nop,TS val 301145612 ecr 301145770], length 0
12:15:50.493995 IP 192.168.250.64.31340 > web-app-db7f7c59-d4xm6.80: Flags [S], seq 124258064, win 28400, options [mss 1420,sackOK,TS val 301146305 ecr 0,nop,wscale 7], length 0
12:15:50.494022 IP web-app-db7f7c59-d4xm6.80 > 192.168.250.64.31340: Flags [S.], seq 3544403648, ack 124258065, win 27760, options [mss 1400,sackOK,TS val 301146463 ecr 301146305,nop,wscale 7], length 0
12:15:50.494189 IP 192.168.250.64.31340 > web-app-db7f7c59-d4xm6.80: Flags [.], ack 1, win 222, options
您还可以看看ksniff工具,这是一个kubectl插件,它利用tcpdump和Wireshark在Kubernetes集群中的任何pod上启动远程捕获。
在我的 OVH 托管 Kubernetes 集群中,我正在尝试公开 NodePort 服务,但看起来无法通过以下方式
我使用此处的说明在 VirtualBox 上创建了一个 3 节点 kubernetes 集群(1 个主 2 个工作线程)。我正在使用法兰绒作为覆盖网络。 我在安装过程中在主服务器上设置了< code > sysctl-w net . bridge . bridge-nf-call-iptables = 1 和< code > sysctl-w net . bridge . bridge-nf-ca
但我也想在集群外访问它。Description输出表示它使用端口30177上的NodePort公开。 但我无法在上访问它
我对kubernetes相当陌生,我正试图在MacBook上使用minikube来编排我的rails应用程序。我的应用程序包括MySQL、Redis和Sidekiq。我在独立的豆荚里运行webapp、sidekiq、redis和数据库。Sidekiq吊舱没有连接到redis吊舱。 sidekiq吊舱的库贝特尔日志是这样说的: 我的webapp.yaml webapp-service.yaml Si
我们在AWS EKS上运行两种类型的服务: null
在AWS EKS上,我有ALB入口控制器,入口资源指向端口32509上的NodePort服务,目标端口80,服务上有。 在这种情况下,外部流量如何在NodePort服务下路由到我的pod? 类似于,ALB