简体   繁体   English

除了 master 和 worker 之外,Kubernetes pods IP 应该可以从外部网络访问或 ping 通

[英]Kubernetes pods IP should be reachable or pingable from external network - apart from master and worker

I have created a deployment with NodePort.我已经使用 NodePort 创建了一个部署。 Pod is created and pod has an IP. Pod 被创建并且 Pod 有一个 IP。 Only one container is running in a pod.只有一个容器在一个 pod 中运行。 I want to access that container/pod IP from external apart from Master or node.我想从除主节点或节点之外的外部访问该容器/吊舱 IP。 Now I'm able to ping the pod IP from master and node, but not from my device.现在我可以从 master 和 node ping pod IP,但不能从我的设备。 Container/pod should be pingable from my device.容器/吊舱应该可以从我的设备上 ping 通。 I'm able to ping my device from my pod/container.我可以从我的 pod/容器 ping 我的设备。

What needs to be done to make the pod IP visible/reachable from the outside?需要做什么才能使 pod IP 从外部可见/可访问?

You need to point to Service port (of type NodePort) on a node, not the pod IP.您需要指向节点上的服务端口(类型为 NodePort),而不是 pod IP。

kubectl get service <my-service>

Check what port did you get.检查你得到了什么端口。 Then get IP of any node of the k8s cluster然后获取k8s集群任意节点的IP

kubectl get nodes

And reach it like并达到它像

telnet <node_ip>:<service_port>

More on service types: https://kubernetes.io/docs/concepts/services-networking/service/更多关于服务类型: https : //kubernetes.io/docs/concepts/services-networking/service/

如果你想访问你的pod,你应该这样做:${node-ip}:${nodeport}。但是你不能通过它的clusterIP访问你的pod,它只用于集群内通信。你可以获得外部IP通过将服务更改为 LoadBalancer,但 IP 由云提供商接收。

I agree with @Max Lobur and @Мартин Петков conclusions, that using NodePort type of Kubernetes services makes it possible to proxy underlying Pod service port to some port from the pool on the corresponded Node, therefore you might be able to reach Kubernetes Pod outside the cluster on Node IP address and related proxy port.我同意@Max Lobur 和@Мартин Петков 的结论,即使用NodePort类型的 Kubernetes 服务可以将底层 Pod 服务端口代理到相应节点上的池中的某个端口,因此您可能能够在外部访问 Kubernetes Pod节点 IP 地址和相关代理端口上的集群。

Alternatively, you can achieve communication with target Kubernetes Pod by applying External IP in a particular service to transmit network traffic to the related Node, however this is quite weighty solution, as it requires some routes to be implemented on external IP to forward network traffic to the nested Kubernetes Node.或者,您可以通过在特定服务中应用外部 IP将网络流量传输到相关节点来实现与目标 Kubernetes Pod 的通信,但这是一个非常重要的解决方案,因为它需要在外部 IP 上实现一些路由以将网络流量转发到嵌套的 Kubernetes 节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM