Kubernetes-如何通过吊挂请求从Pod中的Web服务器访问服务 [英] Kubernetes - How to acces to service from a web server in pod with a rest request
问题描述
我正在寻找使用Kubernetes DNS从Pod中重播Pod的方法.全部都在我的Kubernetes集群中.
I'm looking to use Kubernetes DNS to requetes pods from pods. All is in my Kubernetes cluster.
我想使用来自Web应用程序的http请求者来调用另一个Web应用程序
I would like to use a http requeste from a web app to call another web app
例如,我想从DashboardWebApp调用ProductWebApp
For exemple I would like to call ProductWebApp from DashboardWebApp
我发现kubernetes rest api
I found kubernetes rest api
➜〜kubectl exec -it仪表板-57f598dd76-54s2x-/bin/bash
➜ ~ 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":失败", "message":服务\" product-app \被禁止:用户\" system:anonymous \无法在名称空间" staging \"中获得服务/代理, "reason":"Forbidden", 细节": { "name":"product-app", "kind":服务" }, 代码":403 }%
}, "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
我也找到了这个网址
➜〜curl -XGET product-app.staging.svc.cluster.local/api/product/5bf42b2ca5fc050616640dc6
I found also this url
➜ ~ curl -XGET product-app.staging.svc.cluster.local/api/product/5bf42b2ca5fc050616640dc6
但这也不起作用
那么从吊舱拨打电话到服务的好方法是什么?
So what is the good way to make a call from a pod to service ?
推荐答案
在相同 Kubernetes集群上同时运行 和
For when both ProductWebApp and DashboardWebApp are running on the same Kubernetes cluster:
按照此处所述定义服务.使用type: ClusterIP
服务调用(ProductWebApp);配置服务名称为要调用的URI的调用应用(DashboardWebApp).
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.
例如,假设ProductWebApp位于名为staging
的命名空间中,则为ProductWebApp部署定义一个名为product-app
的服务,然后配置DashboardWebApp以使用此URI调用ProductWebApp:
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
如果ProductWebApp终结点需要,请用https替换http.请注意,服务名称可以与该服务所在的部署的名称相同.
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.
当Kubernetes集群正在运行DNS服务时(大多数集群都在运行),此方法有效-请参见链接,尤其是
This works when the Kubernetes cluster is running a DNS service (and most clusters do) - see this link and specifically the A records section.
这篇关于Kubernetes-如何通过吊挂请求从Pod中的Web服务器访问服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!