Kubernetes - resolve hostname of a service

7/28/2020

I would like to perform a call to my echo-server but I can not figure out what's the hostname of my service:

orion:webanalytics papaburger$ kubectl get services -n web-analytics
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)      AGE
echo-server            ClusterIP   10.100.92.251    <none>        80/TCP       87m
web-api                ClusterIP   10.100.92.250    <none>        8080/TCP     87m

I have tried to reach using kubectl exec -it curl-curl0 -- curl http://web-analytics.echo-server.svc.cluster.local/heythere but it fails:

curl: (6) Couldn't resolve host 'web-analytics.echo-server.svc.cluster.local'

If I change web-analytics.echo-server.svc.cluster.local to cluster ip, it works.

How can I make my pods (web-api) reach the echo server?

edit:

orion:webanalytics papaburger$ kubectl get ep -n web-analytics
NAME                   ENDPOINTS             AGE
echo-server            172.16.187.247:80     95m
web-api                172.16.184.217:8080   95m
-- placplacboom
kubernetes

2 Answers

7/28/2020

it should be like this

the service name is always like this

<service-name>.<namespace-name>.svc.cluster.local

kubectl exec -it curl-curl0 -- curl http://echo-servcer.web-analytics.svc.cluster.local/heythere

or alternative way would be you can directly curl the POD_IP:80

-- Dashrath Mundkar
Source: StackOverflow

7/28/2020

The DNS name is referred incorrectly, it follows the following format

my-svc.my-namespace.svc.cluster-domain.example

Based on the kubectl output, the DNS should be

echo-server.web-analytics.svc.cluster.local

The respective curl will be -

kubectl exec -it curl-curl0 -- curl http://echo-server.web-analytics.svc.cluster.local/heythere
-- Avinash Reddy
Source: StackOverflow