首页 > 解决方案 > FastApi 使用 Python 将请求从 Kubernetes 内部的一个 api 发布到另一个

问题描述

我在 pod 中使用 FastApi 创建了 2 个 API,我需要一个来连接另一个:我在 API A 中有这样的东西:

@router.post(
"/API-A")

response = requests.post(
    "URL I SHOULD ADD BUT IT IS NOT WORKING"
    headers={
        "content-type": "application/json",
    },
    verify=False,
    data=payload.json
).json()

return response

有人告诉我,由于 API B 部署在 kubernetes 中,我应该调用服务名称而不是 DNS,但是,它似乎不起作用。我试过了:

 url= api-service/prices (being prices the endpoint of API B, and api-service the serviceName)

我收到此错误:

Invalid URL 'api-service/prices': No schema supplied.

我做错了吗?这是我第一次在 Kubernetes 中调用 API,所以我真的不知道应该怎么做。

非常感谢您。

标签: pythonrestkubernetesfastapi

解决方案


推荐阅读