1
votes

I'm looking to use Kubernetes DNS to requetes pods from pods. All is in my Kubernetes cluster.

I would like to use a http requeste from a web app to call another web app

For exemple I would like to call ProductWebApp from DashboardWebApp

I found kubernetes rest api

➜ ~ kubectl exec -it dashboard-57f598dd76-54s2x -- /bin/bash

➜ ~ curl -X GET https://4B3449144A41F5488D670E69D41222D.sk1.us-east-1.eks.amazonaws.com/api/v1/namespaces/staging/services/product-app/proxy/api/product/5bf42b2ca5fc050616640dc6 { "kind": "Status", "apiVersion": "v1", "metadata": {

}, "status": "Failure", "message": "services \"product-app\" is forbidden: User \"system:anonymous\" cannot get services/proxy in the namespace \"staging\"", "reason": "Forbidden", "details": { "name": "product-app", "kind": "services" }, "code": 403 }%

I don't understand why it's block

I found also this url
➜ ~ curl -XGET product-app.staging.svc.cluster.local/api/product/5bf42b2ca5fc050616640dc6

But it's also not work

So what is the good way to make a call from a pod to service ?

1

1 Answers

6
votes

For when both ProductWebApp and DashboardWebApp are running on the same Kubernetes cluster:

Define a Service as described here for the app that you want to call (ProductWebApp) using type: ClusterIP service; configure the calling app (DashboardWebApp) with the service name as the URI to call.

For example, assuming ProductWebApp is in a namespace named staging, define a service named product-app for the ProductWebApp deployment and then configure the DashboardWebApp to call ProductWebApp at this URI:

http://product-app.staging.svc.cluster.local/end/point/as/needed

Replace http with https if the ProductWebApp endpoint requires it. Notice that a Service name can be the same as the name of the Deployment for which the service is.

This works when the Kubernetes cluster is running a DNS service (and most clusters do) - see this link and specifically the A records section.