When I am trying to send an HTTP request from one pod to another pod within my cluster, how do I target it? By the cluster IP, service IP, serivce name? I can not seem to find any documentation on this even though it seems like such a big part. Any knowledge would help. Thanks!
Asked
Active
Viewed 6,372 times
1
-
3[Connecting Applications with Services](https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/) in the Kubernetes documentation seems relevant. In general you can use the destination service name as a DNS name. – David Maze May 22 '19 at 22:53
2 Answers
6
DNS for Services and Pods should help you here.
apiVersion: v1
kind: Service
metadata:
name: myservice
namespace: mynamespace
spec:
selector:
name: myapp
type: ClusterIP
ports:
- name: http
port: 80
targetPort: 80
Lets say you have a service defined as such and you are trying to call the service from the same namespace. You can call http://myservice.svc.cluster.local:80
. If you want to call the service from another namespace you can use http://myservice.mynamespace.svc.cluster.local:80

Sean Boczulak
- 131
- 6
2
As @David Maze mentioned, you can find more information about:
- "Connecting Applications with Services and Exposing the Service",
- "testing and debugging",
- "Publishing services and service types"
Shortly:
Please exec into your pod:
kubectl exec -it <your_pod> -- /bin/bash
perform:
nslookup <your_service>
In that way you can check if your service is working using DNS (assuming your service is working in default namespace) you should see:
<your_service>.default.svc.cluster.local
than you can check:
curl http://<your_service>
or
curl http://<your_service>.default.svc.cluster.local

Mark
- 3,644
- 6
- 23