简体   繁体   English

如何在 Cloud Composer 中通过 API 访问 Kubernetes 服务

[英]How to access Kubernetes Service via API in Cloud Composer

I am trying to send an API request to a Kubernetes Service using Cloud Composer.我正在尝试使用 Cloud Composer 向 Kubernetes 服务发送 API 请求。 I have the following snippet:我有以下片段:

def fetchToken():
    ...


def start_application():
keycloak_token = fetchToken()
url = "http://<name>.svc.cluster.local/tasks"

with open("/home/airflow/gcs/dags/src/somefile.json") as f:
    d = json.load(f)

response = requests.put(
    url,
    headers={
        "Authorization": f"Bearer {keycloak_token}",
        "Content-type": "application/json",
    },
    data=json.dumps(d),
)

However, this gives me the following error:但是,这给了我以下错误:

(HTTPConnectionPool(host='<name>.svc.cluster.local', port=80): Max retries exceeded with url: /tasks:8080 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f03e0d97d60>: Failed to establish a new connection: [Errno -2] Name or service not known')); 25941)

Seems like I cannot access as the URL is "svc.cluster.local".好像我无法访问,因为 URL 是“svc.cluster.local”。 Any idea how to access the endpoint?知道如何访问端点吗?

Thanks!谢谢!

Cloud composer is a google service independent from GKE, if you don't want to expose your api to public, you can create an internal load balancer to expose the service in the vpc, so by using the same vpc on cloud composer and GKE, your cloud composer dags could access the API in GKE. Cloud composer 是一个独立于 GKE 的 google 服务,如果您不想将 api 公开,您可以创建一个内部负载均衡器以在 vpc 中公开该服务,因此通过在 cloud composer 和 GKE 上使用相同的 vpc,您的云作曲家 dags 可以访问 GKE 中的 API。

There are many other options and tools to achieve this.还有许多其他选项和工具可以实现这一目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过服务帐户访问 Google Cloud Storage - Google Cloud Storage access via service account 如何在python中直接访问kubernetes服务主机? - How to access kubernetes service host directly in python? 通过 Kubernetes Python 客户端访问 Kubernetes 中的服务 - Accessing a service in Kubernetes via the Kubernetes Python client Google Cloud Composer 在失败时调用 API - Google Cloud Composer call an API on failure 其他谷歌云服务账户的云作曲家身份验证 - Cloud composer authentication of other google cloud service accounts IBM Cloud:如何访问API进行计费和使用? - IBM Cloud: How to access the API for billing and usage? Google Calendar API - 通过服务帐户访问自己的日历 - Google Calendar API - Access own calendar via Service account 如何在云编辑器环境中获取合适的凭据以调用 Google Sheets API? - How can I obtain suitable credentials in a cloud composer environment to make calls to the google sheets API? 如何通过我的 flask 应用程序访问云中的 an.xls(或.csv)? - How to access an .xls (or .csv) in the cloud, via my flask application? 如何通过HTTP身份验证访问datahug API? - How to access datahug API via HTTP Authentication?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM