跳至内容

部署函数

部署函数会为您的函数创建一个 OCI 容器镜像,并将此容器镜像推送到您的镜像仓库。该函数将作为 Knative 服务部署到集群。重新部署函数会更新容器镜像以及在您的集群上运行的生成的 Service。已部署到集群的函数在集群上可以像其他任何 Knative Service 一样访问。

先决条件

  • 您的本地机器上有一个 Docker 守护程序。如果您使用过 Quickstart 安装,则已经提供。

  • 您可以访问容器仓库,并且可以将镜像推送到该仓库。请注意,一些镜像仓库默认将新推送到仓库的镜像设置为私有。如果您是第一次部署函数,则可能需要确保您的镜像设置为公开。

步骤

deploy 命令使用函数项目名称作为 Knative Service 名称。构建函数时,项目名称和镜像仓库名称将用于构建函数的完全限定镜像名称。

在项目目录中运行该命令来部署函数

func deploy --registry <registry>

在项目目录中运行该命令来部署函数

kn func deploy --registry <registry>

预期输出

    🙌 Function image built: <registry>/hello:latest
     Function deployed in namespace "default" and exposed at URL:
    http://hello.default.127.0.0.1.sslip.io

您可以使用 invoke 命令并观察输出,验证您的函数是否已成功部署

func invoke
kn func invoke

预期输出

Received response
POST / HTTP/1.1 hello.default.127.0.0.1.sslip.io
  User-Agent: Go-http-client/1.1
  Content-Length: 25
  Accept-Encoding: gzip
  Content-Type: application/json
  K-Proxy-Request: activator
  X-Request-Id: 9e351834-0542-4f32-9928-3a5d6aece30c
  Forwarded: for=10.244.0.15;proto=http
  X-Forwarded-For: 10.244.0.15, 10.244.0.9
  X-Forwarded-Proto: http
Body:

我们使用分析和 Cookie 来了解网站流量。有关您使用我们网站的信息将与 Google 共享,用于该目的。 了解更多信息。