在云运行作业中使用云函数中的容器

问题描述 投票:0回答:1

我对 gcp 很陌生,我在云函数中创建了一个小测试函数,如下所示:

import functions_framework
import dask.dataframe as dd

@functions_framework.http
def hello_http(request):
    """HTTP Cloud Function.
    Args:
        request (flask.Request): The request object.
        <https://flask.palletsprojects.com/en/1.1.x/api/#incoming-request-data>
    Returns:
        The response text, or any set of values that can be turned into a
        Response object using `make_response`
        <https://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response>.
    """
    id="ok"
    return id

我在cloud shell上测试了该功能,使用:

curl -m 36230 -X POST https://some-url.cloudfunctions.net/index-firestore-2 -H "Authorization: bearer $(gcloud auth print-identity-token)" -H "Content-Type: application/json" -d '{}'

它会按预期输出正确的输出。

现在,我看到在云运行中,有一个

job
接受一个容器并运行更长时间。因此,我创建了一个作业,其中指定
'{}'
作为容器的参数。当我运行这项工作时,它似乎总是出错。所以,

Leave blank to use the entry point command defined in the container image: <left blank>
Arguments passed to the entry point command: '{}' #also tried {} and leaving it blank

但似乎说当我给出“{}”或“{}”时,参数不被识别。如果我将其留空,则不会发生任何事情。确切的错误是:

Error: Got unexpected extra argument ({})

想知道发生了什么,因为它适用于云函数,并且据我所知,云函数的 v2 版本只是云运行的抽象:(

google-cloud-platform google-cloud-functions google-cloud-run
1个回答
0
投票

您必须查看服务以及您想要做什么。让我总结一下(并简化),你就会明白你的误解了

Cloud Functions 是一项方便的服务,可以使用处理请求的代码段(如果是 HTTP 函数)。然后,它添加一个 Flask 层并将整个内容打包在一个容器中。然后容器在 Cloud Functions 服务上提供服务(在第 1 代中

Cloud Run 标准服务于容器。您可以执行与 Cloud Functions 相同的操作,但您必须编写 Flask Web 服务器和 Dockerfile 来创建容器。您必须在部署在 Cloud Run 服务上的容器中公开 Web 服务器

Cloud Run Jobs 还提供容器服务。但这一次,没有 API 访问。这只是一个剧本,一个工作。没有网络服务器和 HTTP 请求。当容器退出(作业结束)时,正在运行的实例将停止


因此,在 Cloud Run Jobs 中使用 Web 服务器(由 Cloud Functions 或其他容器构建器制作)提供容器服务是没有意义的。暴露的端口将永远无法访问,并且容器永远不会结束(直到作业超时和终止)。


回顾您的设计以及您想要实现的目标。

© www.soinside.com 2019 - 2024. All rights reserved.