[英]Can't to talk with other pods using Kubernetes Service
How I understand that I could be able to talk with other pods from a specific pod by sending from within the pod an HTTP request with the fully qualified domain name of the service (FQDN).我如何理解我可以通过从 pod 中发送带有服务的完全限定域名 (FQDN) 的 HTTP 请求来与特定 pod 中的其他 pod 交谈。 The system runs locally with minikube.
系统使用 minikube 在本地运行。
The service's YML -服务的 YML -
apiVersion: v1
kind: Service
metadata:
name: kubia
spec:
sessionAffinity: ClientIP
ports:
- port: 80
targetPort: 8080
selector:
app: kubia
The describe of the service -服务描述——
Name: kubia
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=kubia
Type: ClusterIP
IP: 10.111.178.111
Port: <unset> 80/TCP
TargetPort: 8080/TCP
Endpoints: 172.17.0.7:8080,172.17.0.8:8080,172.17.0.9:8080
Session Affinity: ClientIP
Events: <none>
I'm trying to do that with -我正在尝试通过 -
kubectl exec -it kubia-gqd5l bash
where kubia-gqd5l is the pod.其中 kubia-gqd5l 是吊舱。 In the bash I tried to sent a request by -
在 bash 中,我尝试通过以下方式发送请求 -
curl http://kubia
Where kubia is the name of the service.其中 kubia 是服务的名称。 and I got error -
我得到了错误 -
curl: (6) Could not resolve host: kubia.
curl:(6)无法解析主机:kubia。
It is important to note that I manage to communicate with the service by -重要的是要注意,我设法通过以下方式与服务进行通信 -
kubectl exec kubia-gqd5l -- curl -s http://10.111.178.111
any idea?任何想法?
Have a look at this answer 2 Kubernetes pod communicating without knowing the exposed address , to target a service it's better to add the namespace with the service.看看这个答案2 Kubernetes pod 在不知道暴露地址的情况下进行通信,以服务为目标,最好在服务中添加命名空间。
Kubernetes clusters usually have DNS deployed. Kubernetes 集群通常部署了 DNS。 That allows pod to pod communications within the cluster (among other things) by using the name of the corresponding Kubernetes services.
通过使用相应的 Kubernetes 服务的名称,这允许集群内的 pod 到 pod 通信(除其他外)。 See https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
见https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
Does your Kubernetes cluster/minikube have DNS running?您的 Kubernetes 集群/minikube 是否正在运行 DNS?
Something else to check is the selector in the Service definition - make sure the pod/deployment has the app: kubia
label as specified in the selector.其他需要检查的是服务定义中的选择器 - 确保 pod/deployment 具有
app: kubia
label,如选择器中指定的那样。
Otherwise, and per the doc at the link above, because the lookup of the service is from a pod in the same namespace, it shouldn't be needed to use the namespace along with the service name: (quote) "...Assume a Service named foo in the Kubernetes namespace bar. A Pod running in namespace bar can look up this service by simply doing a DNS query for foo. A Pod running in namespace quux can look up this service by doing a DNS query for foo.bar".否则,根据上面链接中的文档,由于服务的查找来自同一命名空间中的 pod,因此不需要将命名空间与服务名称一起使用:(quote) "...假设Kubernetes 命名空间 bar 中名为 foo 的服务。在命名空间 bar 中运行的 Pod 可以通过简单地对 foo 执行 DNS 查询来查找此服务。在命名空间 quux 中运行的 Pod 可以通过对 foo 执行 ZED5F2BDECBD4BD349D0941 查询来查找此服务。 ”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.