跳至内容

部署 Knative 服务

在本教程中,您将部署一个接受环境变量 TARGET 并打印 Hello ${TARGET}! 的“Hello world” Knative 服务。

通过运行以下命令部署服务

kn service create hello \
--image ghcr.io/knative/helloworld-go:latest \
--port 8080 \
--env TARGET=World

预期输出

Service hello created to latest revision 'hello-0001' is available at URL:
http://hello.default.${LOADBALANCER_IP}.sslip.io
上面 ${LOADBALANCER_IP} 的值取决于您的集群类型,对于 kind 来说将是 127.0.0.1,对于 minikube 则取决于本地隧道。

  1. 将以下 YAML 复制到名为 hello.yaml 的文件中

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: hello
    spec:
      template:
        spec:
          containers:
            - image: ghcr.io/knative/helloworld-go:latest
              ports:
                - containerPort: 8080
              env:
                - name: TARGET
                  value: "World"
    
  2. 通过运行以下命令部署 Knative 服务

    kubectl apply -f hello.yaml
    

    预期输出

    service.serving.knative.dev/hello created
    

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