默认情况下,在 Kubernetes 1.13 中安装了 CoreDNS。
您能告诉我如何通过服务名称在集群中进行 curl 吗?
[root@master ~]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 24h
[root@master ~]# kubectl get services --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-system coredns ClusterIP 10.233.0.3 <none> 53/UDP,53/TCP,9153/TCP 21h
tools nexus-svc NodePort 10.233.17.152 <none> 8081:31991/TCP,5000:31111/TCP,8083:31081/TCP,8082:31085/TCP 14h
[root@master ~]# kubectl describe services nexus-svc --namespace=tools
Name: nexus-svc
Namespace: tools
Labels: tools=nexus
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"tools":"nexus"},"name":"nexus-svc","namespace":"tools"},"spec"...
Selector: tools=nexus
Type: NodePort
IP: 10.233.17.152
Port: http 8081/TCP
.....
所以我得到了正确的答案。
[root@master ~]# curl http://10.233.17.152:8081
<!DOCTYPE html>
<html lang="en">
<head>
<title>Nexus Repository Manager</title>
....
所以没有。
[root@master ~]# curl http://nexus-svc.tools.svc.cluster.local
curl: (6) Could not resolve host: nexus-svc.tools.svc.cluster.local; Unknown error
[root@master ~]# curl http://nexus-svc.tools.svc.cluster.local:8081
curl: (6) Could not resolve host: nexus-svc.tools.svc.cluster.local; Unknown error
谢谢。
最佳答案
coredns
或 kubedns
旨在将服务名称解析为其clusterIP
(普通服务)或对应的 Pod IP( headless 服务)在 kubernetes 集群内部而不是外部。您正在尝试在节点上 curl 服务名称,而不是在 pod 内,因此它无法将服务名称解析为其 clusterIP。
您可以进入 pods 并尝试以下操作:
kubectl exec -it <pod_name> bash
nslookup nexus-svc.tools.svc.cluster.local
它将返回您的集群 IP,这意味着
coredns
工作正常。如果您的 pod 有 curl 实用程序,那么您也可以使用服务名称 curl 它(但仅限于集群内部)如果你想从集群外部访问该服务,该服务已经暴露为
NodePort
因此您可以使用以下方式访问它: curl http://<node_ip>:31991
希望这可以帮助。
关于Kubernetes 1.13,CoreDNS - 集群 curl 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53921281/