部署 Knative 服務¶
在本教學中,您將部署一個「Hello world」Knative 服務,該服務接受環境變數 TARGET
並印出 Hello ${TARGET}!
。
執行指令來部署服務
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