Pod无法卷曲localhost

时间:2020-10-06 07:42:54

标签: elasticsearch kubernetes

在9200端口上的localhost上运行着一个弹性搜索容器,但是从同一主机上的容器中,我无法卷曲localhost 9200端口

@Dao
public interface StudentDAO {
    @Update
    void update(StudentEntity student);
}

/ etc / hosts

[root@jenkins ~]# netstat -tupln | grep 9200
tcp6       0      0 :::9200                 :::*                    LISTEN      4148/docker-proxy


[jenkins@kb-s-9xttg agent]$ curl http://localhost:9200
curl: (7) Failed to connect to ::1: Network is unreachable

我能够# Kubernetes-managed hosts file. 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet fe00::0 ip6-mcastprefix fe00::1 ip6-allnodes fe00::2 ip6-allrouters 192.168.255.23 kbs-9xttg

elastic-search容器不是由Kubernetes管理的,而是在同一主机上运行的。

为什么Pod无法与curl public_host_ip:9200localhost:9200通话?

1 个答案:

答案 0 :(得分:2)

评论摘要:

如果您是在Pod中与本地主机通信,则仅是在与该Pod中的容器通信。

不同Pod中的容器具有不同的IP地址,并且无法使用localhost进行通信。但是,它们可能会在本地主机网络上公开自己的端口,类似于Docker容器正在做的事情(这就是为什么您可以使用本地主机从本地节点进行通信的原因)。

在集群内部,您可以使用Pod IP,但是,如果要与主机对话,则需要为Pod使用主机网络

spec:
   hostNetwork: true

或主机的外部IP。

有关Kubernetes Networking in the docsthis blog post的更多信息。

相关问题