[英]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.