使用Nodeport访问pod Kubernetes Service中的api

问题描述 投票:0回答:1

我在端口 12345 上创建了一个 nodeport 服务,以访问通过 pod 部署的在节点 6666 上运行的 api。 Pod 部署在多个节点。

 ports:
   - port: 8181
     targetPort: 6666
     nodePort: 12345
     protocol: TCP

为了获取节点的ip,通过运行

   kubectl get nodes -o wide

获取节点的内/外ip。 因此,生成的curl命令是

   http://<node internal ip>:12345/

问题在于,每次执行 ping 操作时,都会循环所有节点,通过开放端口运行。

如何确保使用内部 ip 的 ping 只命中一个节点及其上运行的 pod 服务?

提前致谢。!!

kubernetes kubectl kubernetes-nodeport
1个回答
0
投票

我能够通过添加

解决上述问题
 externalTrafficPolicy: "Local"

在服务定义中。这样,对节点 ip 和 api 的 ping 不会到达其他节点,而是限制在本地节点。

© www.soinside.com 2019 - 2024. All rights reserved.