How to Access rest api (deployed in k8 cluster) via service name

949 Views Asked by At

Deployed a rest API(go lang) in kubernetes cluster and also created a service for the pod.

i need to access the rest API via service name or service URL?

1

There are 1 best solutions below

2
On

It depends from where are you accessing the service.

If you are accessing from the kubernetes cluster nodes, you can access through service IP; curl <service-ip> should provide access to your rest API.

If you are accessing the service from another pod, then you can use internal kubernetes DNS resolution. Something like curl <service-name>.<namespace>.svc.cluster.local should access your rest API.

If you want to access rest API outside of the cluster, you need a load balancer with the IP of the cluster external network (the network where cluster resides). If you have deployed cluster on-premise, you may consider using metallb for managing external IPs. If the cluster is deployed in the cloud, then you can use cloud provided IPs.