简体   繁体   English

其他主机无法访问 Pod

[英]Pods not accessible from another host

I created a cluster with several Raspberry Pi following this tutorial我按照本教程创建了一个包含多个 Raspberry Pi 的集群

I'm stuck with a problem.我遇到了一个问题。

I have a master node and a slave.我有一个主节点和一个从节点。 I create deployment and a service for Nginx (for testing purpose).我为 Nginx 创建部署和服务(用于测试目的)。

Here is the deployment file这是部署文件

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
    app: nginx
spec:
replicas: 1
selector:
    matchLabels:
    app: nginx
template:
    metadata:
    labels:
        app: nginx
    spec:
    containers:
    - name: nginx
        image: nginx
        ports:
        - containerPort: 80

Here is the service file这是服务文件

apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
    app: nginx
spec:
type: NodePort
ports:
    - port: 80
    protocol: TCP
selector:
    app: nginx

I cannot reach the service from outside the cluster.我无法从集群外部访问该服务。

Here is the IP Configuration (all on wifi):这是 IP 配置(全部在 wifi 上):

Master : 192.168.1.200
Slave  : 192.168.1.201

From SSH on the slave I can, ´curl 127.0.0.1:30187´ and also ´curl 192.168.1.201:30187´, but from the master or my personnal computer it can't get the Nginix default page.从从机上的 SSH 我可以,'curl 127.0.0.1:30187' 和 'curl 192.168.1.201:30187',但从主机或我的个人计算机它无法获得 Nginix 默认页面。 Instead I have this issue: ´curl: (7) Failed to connect to 192.168.1.201 port 30187: Connection timed out´相反,我有这个问题:'curl:(7)无法连接到 192.168.1.201 端口 30187:连接超时'

Can someone help me on this?有人可以帮我吗?

I finally find the answer on this .我终于在这个问题上找到了答案。

I had to allow the forwarding on iptables .我不得不允许在iptables上转发。

iptables -P FORWARD ACCEPT

Best regards.此致。

I think you should specify a targetPort and a nodePort in your service.yaml:我认为你应该在你的 service.yaml 中指定一个targetPort和一个nodePort

apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
    app: nginx
spec:
type: NodePort
ports:
    - port: 80
    - targetPort : 80
    - nodePort: 32080
    protocol: TCP
selector:
    app: nginx

Now, the port 80 of the container nginx in your pod nginx is visible to other pods on targetPort 80 thanks to the service.现在,由于该服务,您的 pod nginx中的容器nginx端口80 对targetPort 80 上的其他 pod 可见。 But it is also exposed to the outside world on port 32080. You should then be able to access 192.168.1.200:32080但是它也在32080端口上暴露给外界。然后你应该可以访问192.168.1.200:32080

NodePort service can be accessed via all the nodes of the nodes. NodePort服务可以通过节点的所有节点访问。 Once you create NodePort Service, You should be able to access it from local but it will not be accessible to the external world if you are using cloud.创建 NodePort 服务后,您应该可以从本地访问它,但如果您使用云,则外部世界将无法访问它。 This is because of firewall rules.这是因为防火墙规则。

For example, If you are using Google Cloud Platform We need to change firewall rules.例如,如果您使用的是 Google Cloud Platform,我们需要更改防火墙规则。 so that external IPs can access the cluster.以便外部 IP 可以访问集群。

So For you to access cluster, port forwarding should be enabled.所以为了让你访问集群,应该启用端口转发。 So check your firewall settings and try it again.因此,请检查您的防火墙设置并重试。 if still you can not able to access it.如果仍然无法访问它。 put a comment.发表评论。

Thanks.谢谢。

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

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