Dolphin
Dolphin

Reputation: 38885

how to access eureka by dns name in kubernetes cluster

I am deploy eureka in kubernetes(v1.15.2) cluster.Now I want to using my app pod register to eureka by domain name,first I try this way:

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

It not works.I am login my app pod using this command:

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

and using curl command to access cluster's eureka this way:

  / # 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

but using this way works:

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

But I think the domain or dns way is better because the ip could floating in the future. So what is the right way to register to eureka using dns? My coredns in the namespace kube-sytem,and my eureka service and app pod in dabai-fat namespace. By the way,this is my eureka service info in kubernetes:

enter image description here

Upvotes: 1

Views: 250

Answers (2)

Dolphin
Dolphin

Reputation: 38885

Check the service and change the url to http://eureka.dabai-fat.svc.cluster.local:8761, It works.

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

this is service check command output:

[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

Upvotes: 0

Arghya Sadhu
Arghya Sadhu

Reputation: 44637

Do you have service with name eureka-0.eureka in dabai-fat namespace ? You can check it via kubectl get svc -n dabai-fat.

Upvotes: 2

Related Questions