9.3. 使用 Knative Client 的基本工作流
使用该基本工作流在服务上创建、读取、更新、删除 (CRUD) 操作。以下示例部署一个简单的 Hello World 服务,该服务可读取环境变量 TARGET
并打印其输出。
流程
通过一个镜像,在
default
命名空间内创建一个服务。$ kn service create hello --image gcr.io/knative-samples/helloworld-go --env TARGET=Knative Creating service 'hello' in namespace 'default': 0.085s The Route is still working to reflect the latest desired specification. 0.101s Configuration "hello" is waiting for a Revision to become ready. 11.590s ... 11.650s Ingress has not yet been reconciled. 11.726s Ready to serve. Service 'hello' created with latest revision 'hello-gsdks-1' and URL: http://hello.default.apps-crc.testing
列出该服务。
$ kn service list NAME URL LATEST AGE CONDITIONS READY REASON hello http://hello.default.apps-crc.testing hello-gsdks-1 8m35s 3 OK / 3 True
使用
curl
服务端点命令检查该服务是否正在工作:$ curl http://hello.default.apps-crc.testing Hello Knative!
更新该服务。
$ kn service update hello --env TARGET=Kn Updating Service 'hello' in namespace 'default': 10.136s Traffic is not yet migrated to the latest revision. 10.175s Ingress has not yet been reconciled. 10.348s Ready to serve. Service 'hello' updated with latest revision 'hello-dghll-2' and URL: http://hello.default.apps-crc.testing
现在,该服务的环境变量
TARGET
设置为Kn
。描述该服务。
$ kn service describe hello Name: hello Namespace: default Age: 13m URL: http://hello.default.apps-crc.testing Address: http://hello.default.svc.cluster.local Revisions: 100% @latest (hello-dghll-2) [2] (1m) Image: gcr.io/knative-samples/helloworld-go (pinned to 5ea96b) Conditions: OK TYPE AGE REASON ++ Ready 1m ++ ConfigurationsReady 1m ++ RoutesReady 1m
删除该服务。
$ kn service delete hello Service 'hello' successfully deleted in namespace 'default'.
然后您可使用
list
命令来验证hello
服务是否已被删除。$ kn service list hello No services found.