Skip to content

部署 Knative 服务

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

运行命令部署服务:

kn service create hello \
--image gcr.io/knative-samples/helloworld-go \
--port 8080 \
--env TARGET=World

Expected output

Service hello created to latest revision 'hello-world' is available at URL:
http://hello.default.${LOADBALANCER_IP}.sslip.io
The value of ${LOADBALANCER_IP} above depends on your type of cluster, for kind it will be 127.0.0.1 for minikube depends on the local tunnel.

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

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: hello
    spec:
      template:
        spec:
          containers:
            - image: gcr.io/knative-samples/helloworld-go
              ports:
                - containerPort: 8080
              env:
                - name: TARGET
                  value: "World"
    
  2. 运行命令部署Knative Service:

    kubectl apply -f hello.yaml
    

    Expected output

    service.serving.knative.dev/hello created
    
Back to top

We use analytics and cookies to understand site traffic. Information about your use of our site is shared with Google for that purpose. Learn more.

× OK