新四季網

knd操作教程(Knative快捷操作命令Kn)

2023-05-29 22:28:28 1

knd操作教程?簡介: kn 是 Knative 命令行操作客戶端 通過 kn 可以方便的操作Knative 相關的資源,接下來我們就來聊聊關於knd操作教程?以下內容大家不妨參考一二希望能幫到您!

knd操作教程

簡介: kn 是 Knative 命令行操作客戶端。 通過 kn 可以方便的操作Knative 相關的資源。

安裝 Kn

可以通過官方獲取對應的 Kn 二進位• macOS• Linux• Windowskn 會與 kubectl 使用同樣的config 文件,默認使用 $HOME/.kube/config

服務管理

使用 Kn 命令可以執行: list, create, delete, apply, 和 update 操作Knative services.

創建服務

使用 create 命令:kn service create示例:

$ 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

使用 apply 命令:kn service apply示例:

# 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

查看服務

查詢服務列表示例:

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

查詢服務詳情示例:

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

或者以 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: "2020-12-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: 100 revisionName: helloworld-go-cvclp-2 url: http://helloworld-go.default.example.com

更新服務(創建新版本)

使用 update 命令:kn service update NAME示例:

$ 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

使用 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

刪除服務

示例:

kn service delete helloworld-go

版本管理查看版本

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

查看版本詳情

$ 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 3m I Active 2m NoTraffic

刪除版本

$ kn revision delete helloworld-go-pyqqz-1Revision '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

作者:元毅

本文為阿里雲原創內容,未經允許不得轉載

,
同类文章
葬禮的夢想

葬禮的夢想

夢見葬禮,我得到了這個夢想,五個要素的五個要素,水火只好,主要名字在外面,職業生涯良好,一切都應該對待他人治療誠意,由於小,吉利的冬天夢想,秋天的夢是不吉利的
找到手機是什麼意思?

找到手機是什麼意思?

找到手機是什麼意思?五次選舉的五個要素是兩名士兵的跡象。與他溝通很好。這是非常財富,它擅長運作,職業是仙人的標誌。單身男人有這個夢想,主要生活可以有人幫忙
我不怎麼想?

我不怎麼想?

我做了什麼意味著看到米飯烹飪?我得到了這個夢想,五線的主要土壤,但是Tu Ke水是錢的跡象,職業生涯更加真誠。他真誠地誠實。這是豐富的,這是夏瑞的巨星
夢想你的意思是什麼?

夢想你的意思是什麼?

你是什​​麼意思夢想的夢想?夢想,主要木材的五個要素,水的跡象,主營業務,主營業務,案子應該抓住魅力,不能疏忽,春天夢想的吉利夢想夏天的夢想不幸。詢問學者夢想
拯救夢想

拯救夢想

拯救夢想什麼意思?你夢想著拯救人嗎?拯救人們的夢想有一個現實,也有夢想的主觀想像力,請參閱週宮官方網站拯救人民夢想的詳細解釋。夢想著敵人被拯救出來
2022愛方向和生日是在[質量個性]中

2022愛方向和生日是在[質量個性]中

[救生員]有人說,在出生88天之前,胎兒已經知道哪天的出生,如何有優質的個性,將走在什麼樣的愛情之旅,將與生活生活有什么生活。今天
夢想切割剪裁

夢想切割剪裁

夢想切割剪裁什麼意思?你夢想切你的手是好的嗎?夢想切割手工切割手有一個真正的影響和反應,也有夢想的主觀想像力。請參閱官方網站夢想的細節,以削減手
夢想著親人死了

夢想著親人死了

夢想著親人死了什麼意思?你夢想夢想你的親人死嗎?夢想有一個現實的影響和反應,還有夢想的主觀想像力,請參閱夢想世界夢想死亡的親屬的詳細解釋
夢想搶劫

夢想搶劫

夢想搶劫什麼意思?你夢想搶劫嗎?夢想著搶劫有一個現實的影響和反應,也有夢想的主觀想像力,請參閱週恭吉夢官方網站的詳細解釋。夢想搶劫
夢想缺乏缺乏紊亂

夢想缺乏缺乏紊亂

夢想缺乏缺乏紊亂什麼意思?你夢想缺乏異常藥物嗎?夢想缺乏現實世界的影響和現實,還有夢想的主觀想像,請看官方網站的夢想組織缺乏異常藥物。我覺得有些東西缺失了