简体   繁体   English

无法从 kube.netes 主节点访问服务

[英]Unable to access to service from kubernetes master node

[root@kubemaster ~]# kubectl get pods -o wide
NAME                             READY   STATUS    RESTARTS   AGE   IP             NODE          NOMINATED NODE   READINESS GATES
pod1deployment-c8b9c74cb-hkxmq   1/1     Running   0          12s   192.168.90.1   kubeworker1   <none>           <none>

[root@kubemaster ~]# kubectl logs pod1deployment-c8b9c74cb-hkxmq
2020/05/16 23:29:56 Server listening on port 8080

[root@kubemaster ~]# kubectl get service -o wide
NAME          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE   SELECTOR
kubernetes    ClusterIP   10.96.0.1        <none>        443/TCP   13m   <none>
pod1service   ClusterIP   10.101.174.159   <none>        80/TCP    16s   creator=sai

Curl on master node:主节点上的 Curl:

[root@kubemaster ~]# curl -m 2 -v -s http://10.101.174.159:80
* About to connect() to 10.101.174.159 port 80 (#0)
*   Trying 10.101.174.159...
* Connection timed out after 2001 milliseconds
* Closing connection 0

Curl on worker node 1 is sucessfull for cluster IP ( this is the node where pod is running )工作节点 1 上的 Curl 对于集群 IP 是成功的(这是运行 pod 的节点)

[root@kubemaster ~]# ssh kubeworker1 curl -m 2 -v -s http://10.101.174.159:80
Hello, world!
Version: 1.0.0
Hostname: pod1deployment-c8b9c74cb-hkxmq

Curl fails on other worker node as well: Curl 在其他工作节点上也失败:

[root@kubemaster ~]# ssh kubeworker2 curl -m 2 -v -s http://10.101.174.159:80
* About to connect() to 10.101.174.159 port 80 (#0)
*   Trying 10.101.174.159...
* Connection timed out after 2001 milliseconds
* Closing connection 0

I was facing the same issue so this is what I did and it worked:我遇到了同样的问题,所以这就是我所做的并且有效:

Brief: I am running 2 VMs for a 2 Node cluster.简介:我正在为一个 2 节点集群运行 2 个虚拟机。 1 Master Node and 1 Worker Node. 1 个主节点和 1 个工作节点。 A Deployment is running on the worker node. Deployment 正在工作节点上运行。 I wanted to curl from the master node so that I can get response from my application running inside a pod on the worker node.我想从主节点发送 curl,以便我可以从工作节点上的 pod 中运行的应用程序获得响应。 For that I deployed a service on the worker node which then exposed those set of pods inside the cluster.为此,我在工作节点上部署了一项服务,然后在集群内公开了这些 pod 集。

Issue: After deploying the service and doing Kubectl get service , it provided me with ClusterIP of that service and a port (BTW I used NodePort instead of Cluster IP when writing the service.yaml).问题:部署服务并执行Kubectl get service后,它为我提供了该服务的ClusterIP和一个端口(顺便说一句,我在编写 service.yaml 时使用NodePort而不是 Cluster IP)。 But when curling on that IP address and port it was just hanging and then after sometime giving timeout.但是当在那个 IP 地址和端口上卷曲时,它只是挂起,然后在一段时间后超时。

Solution: Then I tried to look at the hierarchy.解决方案:然后我尝试查看层次结构。 First I need to contact the Node on which service is located then on the port given by the NodePort (ie The one between 30000-32767) so first I did Kubectl get nodes -o wide to get the Internal IP address of the required Node (mine was 10.0.1.4) and then I did kubectl get service -o wide to get the port (the one between 30000-32767) and curled it.首先,我需要联系服务所在的节点,然后联系 NodePort 给定的端口(即 30000-32767 之间的端口),所以首先我执行了Kubectl get nodes -o wide以获取所需节点的内部 IP 地址(我的是 10.0.1.4) 然后我做了kubectl get service -o wide来获取端口(30000-32767 之间的那个)并卷曲它。 So my curl command was -> curl http://10.0.1.4:30669 and I was able to get the output.所以我的 curl 命令是 -> curl http://10.0.1.4:30669我能够得到 output。

First of all, you should always be using Service DNS instead of Cluster/dynamic IPs to access the application deployed.首先,您应该始终使用服务 DNS 而不是集群/动态 IP 来访问部署的应用程序。 The service DNS would be < service-name >.< service-namespace >.svc.cluster.local , cluster.local is the default Kube.netes cluster name, if not changed otherwise.服务 DNS 将是< service-name >.< service-namespace >.svc.cluster.localcluster.local是默认的 Kube.netes 集群名称,如果不另外更改的话。

Now coming to the service accessibility, it may be DNS issues.现在谈到服务可访问性,可能是 DNS 问题。 What you can do is try to check the kube-dns pod logs in kube-system namespace.您可以做的是尝试检查kube-system命名空间中的kube-dns pod 日志。 Also, try to curl from a standalone pod.另外,尝试从独立的 pod 到 curl。 If that's working.如果那行得通。

kubectl run --generator=run-pod/v1 bastion --image=busybox

kubectl exec -it bastion bash

curl -vvv pod1service.default.svc.cluster.local

If not the further questions would be, where is the cluster and how it was created?如果不是,那么进一步的问题是,集群在哪里以及它是如何创建的?

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

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