简介:kn是Knative命令行操作客户机。通过Kn可以轻松操作与Knative相关的资源。
安装Kn
相应的Kn二进制文件可以通过公式获得
Mac OS
Linux
Windows
Kn使用config文件,如kubectl。默认值为$HOME/。kube/config
服务管理
使用Kn命令执行list、create、delete、apply和update操作Knative services。
创建服务
使用Create命令:
Kn service create
例如:
$ kn service create hello world-go-env target=k native-image regi
yuncs . com/k native-sample/hello world-go :73 fbdd 56
creating service ' hello world-go ' in namespace ' default ' :
0.116s the route is still working to reflect the latest desired specification .
0.216s configuration ' hello world-go ' is waiting for a revision to become ready .
3.075s.
3.149s ingress has not yet been reconciled .
3.299s.
3.762s Ready to serve .
service ' hello world-go ' created to latest revision ' hello world-go-pyqz-1 ' is available at URL :
使用Apply命令:
Kn service apply
例如:
# create an initial service with using ' kn service apply ',if the service has not
# been already created
Knservice apply s0-image regi
# apply the service again which is a no-operation if none of the options changed
Knservice apply s0-image regi
# add an environment variable to your service . note,that you have to always fully
# specify all parameters(in contrast to ' kn service update)
kn service apply s 0-image regi-env target=k native
# read the service declaration from a file
Knservice apply s0-filename my-查看服务
查询服务列表示例:
Kn service list
name URL latest age conditions ready reason
hello world-go hello world-go-pyqz-1 55s 3 ok/3 true查询服务详细资料范例:
Kn service describe helloworld-go
Name: helloworld-go
Namespace: default
Age: 14m米
URL:
Revisions:
100% @ latest(hello world-go-cvclp-2)[2](9m)
Image: regi (pinned to 032b80)
Conditions:
OK TYPE AGE REASON
雷迪9m
ConfigurationsReady 9m
以RoutesReady 9m或YAML显示详细信息:
$ kn service describe hello world-go-o YAML
Api版本3360
Kind :服务
元数据:
Annotations:
: 1041208914252405-1606806762 : 1041208914252405-1606806762 creationTimestamp: "2020-12-09T06:07:41Z" generation: 2 name: helloworld-go namespace: default resourceVersion: "39555635" selfLink: /apis//namespaces/default/services/helloworld-go uid: 763e8214-7c2d-476c-bd88-40b32a30597d spec: template: metadata: annotations: client.knative.dev/user-image: regi creationTimestamp: null name: helloworld-go-cvclp-2 spec: containerConcurrency: 0 containers: - env: - name: TARGET value: knative image: regi name: user-container readinessProbe: successThreshold: 1 tcpSocket: port: 0 resources: {} timeoutSeconds: 300 traffic: - latestRevision: true percent: 100 status: address: url: conditions: - lastTransitionTime: "2020-12-09T06:13:33Z" status: "True" type: ConfigurationsReady - lastTransitionTime: "2020-12-09T06:13:34Z" status: "True" type: Ready - lastTransitionTime: "2020-12-09T06:13:34Z" status: "True" type: RoutesReady latestCreatedRevisionName: helloworld-go-cvclp-2 latestReadyRevisionName: helloworld-go-cvclp-2 observedGeneration: 2 traffic: - latestRevision: true percent: 100 revisionName: helloworld-go-cvclp-2 url:更新服务(创建新版本)
使用 update 命令:
kn service update NAME
示例:
$ kn service update helloworld-go --image regi
Updating Service 'helloworld-go' in namespace 'default':
3.609s Traffic is not yet migrated to the latest revision.
3.631s Ingress has not yet been reconciled.
4.066s Ready to serve.
Service 'helloworld-go' updated to latest revision 'helloworld-go-cvclp-2' is available at URL:
使用 apply 也可进行更新服务
kn service apply
# Add an environment variable to your service. Note, that you have to always fully
# specify all parameters (in contrast to 'kn service update')
kn service apply s0 --image regi --env TARGET=knative
删除服务
示例:
kn service delete helloworld-go
版本管理
查看版本
kn revision list
NAME SERVICE TRAFFIC TAGS GENERATION AGE CONDITIONS READY REASON
helloworld-go-cvclp-2 helloworld-go 100% 2 40s 4 OK / 4 True
helloworld-go-pyqqz-1 helloworld-go 1 6m29s 3 OK / 4 True
查看版本详情
$ kn revision describe helloworld-go-cvclp-2
Name: helloworld-go-cvclp-2
Namespace: default
Age: 3m
Image: regi (pinned to 032b80)
Env: TARGET=knative
Service: helloworld-go
Conditions:
OK TYPE AGE REASON
++ Ready 3m
++ ContainerHealthy 3m
++ ResourcesAvailable 3m
I Active 2m NoTraffic
删除版本
$ kn revision delete helloworld-go-pyqqz-1
Revision 'helloworld-go-pyqqz-1' deleted in namespace 'default'.
其它
除了上面介绍的 service、revision。 Kn 还支持如下的资源操作, 有兴趣的可以自己试用一下。
• kn broker - 管理事件 brokers
• kn channel - 管理事件 channels
• kn route - 管理服务路由 routes
• kn source - 管理事件源 sources
• kn trigger - 管理事件 triggers
作者:元毅
本文为阿里云原创内容,未经允许不得转载
1.《【kn】Knative快捷命令Kn简介》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。
2.《【kn】Knative快捷命令Kn简介》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。
3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/auto/2977227.html