如何在Kubernetes集群中通过DNS名称访问Eureka

时间:2020-02-03 17:19:17

标签: kubernetes

我正在kubernetes(v1.15.2)集群中部署eureka。现在,我想使用我的应用程序pod寄存器通过域名注册到eureka,首先尝试这种方式:

http://eureka-0.eureka.dabai-fat.svc.cluster.local:8761

不起作用。我使用以下命令登录我的应用程序窗格:

/opt/k8s/bin/kubectl exec -ti soa-room-service-6c4448dfb6-grhtb -n dabai-fat /bin/sh

并使用curl命令以这种方式访问​​集群的eureka:

  / # curl http://eureka-0.eureka.dabai-fat.svc.cluster.local:8761
curl: (6) Could not resolve host: eureka-0.eureka.dabai-fat.svc.cluster.local

但是使用这种方式有效:

/ # curl http://172.30.224.17:8761
{"timestamp":"2020-02-03T17:10:23.037+0000","status":401,"error":"Unauthorized","message":"Unauthorized","path":"/"}

但是我认为域或dns方式更好,因为ip将来可能会浮动。那么,使用dns注册到eureka的正确方法是什么?我的coredns位于命名空间kube-sytem中,而我的eureka服务和应用程序容器位于dabai-fat命名空间中。顺便说一下,这是我在kubernetes中的尤里卡服务信息:

enter image description here

2 个答案:

答案 0 :(得分:2)

您在eureka-0.eureka命名空间中使用名称为dabai-fat的服务吗?您可以通过kubectl get svc -n dabai-fat进行检查。

答案 1 :(得分:0)

检查服务并将URL更改为http://eureka.dabai-fat.svc.cluster.local:8761,它可以正常工作。

/ # curl http://eureka.dabai-fat.svc.cluster.local:8761
{"timestamp":"2020-02-03T17:29:08.045+0000","status":401,"error":"Unauthorized","message":"Unauthorized","path":"/"}

这是服务检查命令输出:

[root@ops001 ~]# kubectl get svc -n dabai-fat
NAME                       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
eureka                     ClusterIP   None             <none>        8761/TCP,8081/TCP   2d
soa-auth-service           ClusterIP   10.254.84.39     <none>        11013/TCP           2d8h