部署 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
则取决于本地隧道。
-
将以下 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"
-
通过运行以下命令部署 Knative 服务
kubectl apply -f hello.yaml
预期输出
service.serving.knative.dev/hello created