Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Knative Shortcut Command Kn

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to use the Knative shortcut command Kn, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Kn is the Knative command line operation client. Through kn, you can easily manipulate Knative-related resources.

Install Kn

The corresponding Kn binary can be obtained officially.

MacOS

Linux

Windows

Kn uses the same config file as kubectl, using $HOME/.kube/config by default

Service management

Use the Kn command to execute: list, create, delete, apply, and update operation Knative services.

Create a service

Use the create command:

Kn service create

Example:

Kn service create helloworld-go-- env TARGET=knative-- image registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56yuncs.com/knative-sample/helloworld-go:73fbdd56Creating service 'helloworld-go' in namespace' default': 0.116s The Route is still working to reflect the latest desired specification. 0.216s Configuration "helloworld-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 'helloworld-go' created to latest revision' helloworld-go-pyqqz-1' is available at URL: http://helloworld-go.default.example.com

Use the apply command:

Kn service apply

Example:

# Create an initial service with using'kn service apply', if the service has not# been already createdkn service apply s0-- image registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56# Apply the service again which is a no-operation if none of the options changedkn service apply s0-- image registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56# 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 registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56-env TARGET=knative# Read the service declaration from a filekn service apply S0-filename my-svc.yml

View Servic

Query service column example:

Kn service listNAME URL LATEST AGE CONDITIONS READY REASONhelloworld-go http://helloworld-go.default.example.com helloworld-go-pyqqz-1 55s 3 OK / 3 True

Example of query service details:

Kn service describe helloworld-goName: helloworld-goNamespace: defaultAge: 14mURL: http://helloworld-go.default.example.comRevisions: 100% @ latest (helloworld-go-cvclp-2) [2] (9m) Image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8 (pinned to 032b80) Conditions: OK TYPE AGE REASON + + Ready 9m + + ConfigurationsReady 9m + + RoutesReady 9m

Or show the details in yaml:

$kn service describe helloworld-go-oyamlapiVersion: serving.knative.dev/v1kind: Servicemetadata: annotations: serving.knative.dev/creator: 1041208914252405-1606806762 serving.knative.dev/lastModifier: 1041208914252405-1606806762 creationTimestamp: "202012-09T06:07:41Z" generation: 2 name: helloworld-go namespace: default resourceVersion: "39555635" selfLink: / apis/serving.knative.dev/v1/namespaces/default/services/helloworld-go uid: 763e8214-7c2d-476c-bd88-40b32a30597dspec: template: Metadata: annotations: client.knative.dev/user-image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8 creationTimestamp: null name: helloworld-go-cvclp-2 spec: containerConcurrency: 0 containers:-env:-name: TARGET value: knative image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8 name: User-container readinessProbe: successThreshold: 1 tcpSocket: port: 0 resources: {} timeoutSeconds: 300 traffic:-latestRevision: true percent: 100status: address: url: http://helloworld-go.default.svc.cluster.local 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: 100revisionName: helloworld-go-cvclp-2 url: http://helloworld-go.default.example.com

Update service (create a new version)

Use the update command:

Kn service update NAME

Example:

$kn service update helloworld-go-- image registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8Updating 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: http://helloworld-go.default.example.com

Update services can also be made using 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 registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8-env TARGET=knative

Delete a service

Example:

Kn service delete helloworld-go version management

View version

Kn revision listNAME SERVICE TRAFFIC TAGS GENERATION AGE CONDITIONS READY REASONhelloworld-go-cvclp-2 helloworld-go 100% 2 40s 4 OK / 4 Truehelloworld-go-pyqqz-1 helloworld-go 1 6m29s 3 OK / 4 True

View version details

$kn revision describe helloworld-go-cvclp-2Name: helloworld-go-cvclp-2Namespace: defaultAge: 3mImage: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8 (pinned to 032b80) Env: TARGET=knativeService: helloworld-goConditions: OK TYPE AGE REASON + + Ready 3m + + ContainerHealthy 3m + + ResourcesAvailable 3mI Active 2m NoTraffic

Delete version

$kn revision delete helloworld-go-pyqqz-1Revision 'helloworld-go-pyqqz-1' deleted in namespace' default'. Other

Except for service and revision introduced above. Kn also supports the following resource operations. If you are interested, you can try it yourself.

Kn broker-manage event brokers

Kn channel-manage event channels

Kn route-Management Service routing routes

Kn source-manage event source sources

Kn trigger-manage event triggers

After reading the above, do you have any further understanding of how to use the Knative shortcut command Kn? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report