Knative 快捷操作命令 Kn 介绍

简介: kn 是 Knative 命令行操作客户端。 通过 kn 可以方便的操作Knative 相关的资源。

kn 是 Knative 命令行操作客户端。 通过 kn 可以方便的操作Knative 相关的资源。

安装 Kn

可以通过官方获取对应的 Kn 二进制
macOS
Linux
Windows
kn 会与 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:73fbdd56
yuncs.com/knative-sample/helloworld-go:73fbdd56
Creating 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 created
kn 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 changed
kn 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 file
kn service apply s0 --filename my-svc.yml

查看服务

查询服务列表示例:

kn service list
NAME            URL                                        LATEST                  AGE   CONDITIONS   READY   REASON
helloworld-go   http://helloworld-go.default.example.com   helloworld-go-pyqqz-1   55s   3 OK / 3     True

查询服务详情示例:

kn service describe helloworld-go
Name:       helloworld-go
Namespace:  default
Age:        14m
URL:        http://helloworld-go.default.example.com
Revisions:
  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 -oyaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  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-40b32a30597d
spec:
  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: 100
status:
  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:160e4dc8
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:
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 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:      registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8 (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

目录
相关文章
|
存储 小程序 UED
微信小程序代码包限制2M 怎么解决?
微信小程序代码包限制2M 怎么解决?
1550 1
|
2月前
|
存储 弹性计算 人工智能
阿里云服务器 ECS 规格族解析:CPU 型号差异与性能参数对比
在阿里云 ECS 实例选型中,“规格族” 是决定性能、成本与适用场景的核心要素。许多用户会疑惑:相同 vCPU 与内存配置下,不同规格族为何价格差异显著?CPU 型号和主频究竟有何区别?本文结合阿里云今年最新实例迭代信息(如第九代 Intel 实例、AMD Turin 架构实例),从规格族定义、CPU 差异、性能参数对比三大维度展开解析,帮助用户精准匹配业务需求。
|
Kubernetes API 容器
k8s restful api 访问
restful api访问k8s集群,增删改查信息,做界面二次开发。需要预先创建访问权限的配置。 官网api文档https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.
10939 1
|
编解码 数据可视化 IDE
【Python篇】matplotlib超详细教程-由入门到精通(下篇)1
【Python篇】matplotlib超详细教程-由入门到精通(下篇)
338 3
|
项目管理 iOS开发 UED
Mac用户必备的任务管理软件!三款高效工具推荐
本文介绍了Mac系统在项目管理和任务管理方面的独特优势,包括用户体验、系统生态整合和隐私安全等方面。针对Mac用户的需求,推荐了三款高效任务管理软件:板栗看板、OmniFocus和Things 3。板栗看板适合团队协作,OmniFocus适合高需求的个人用户,Things 3则以简洁美观的界面和易用性著称。文章详细分析了每款软件的特点和适用场景,帮助用户选择最合适的工具。
823 6
|
机器学习/深度学习 人工智能 自然语言处理
【活动】人工智能:前沿科技中的创业机遇与挑战
本文探讨了人工智能领域的创业机遇与挑战。AI技术的快速发展,如深度学习、自然语言处理等,已广泛应用于医疗、金融、制造等行业。未来创业机会包括AI基础设施、垂直行业解决方案、伦理安全领域及AI与其他技术的融合创新。然而,创业者需面对技术壁垒、数据获取、市场接受度、商业模式创新及政策伦理挑战。要在AI领域成功创业,需紧跟技术趋势,深挖行业需求,创新商业模式,并妥善应对各种挑战。
1142 6
|
存储 人工智能 缓存
探索AIGC未来:CPU源码优化、多GPU编程与中国算力瓶颈与发展
近年来,AIGC的技术取得了长足的进步,其中最为重要的技术之一是基于源代码的CPU调优,可以有效地提高人工智能模型的训练速度和效率,从而加快了人工智能的应用进程。同时,多GPU编程技术也在不断发展,大大提高人工智能模型的计算能力,更好地满足实际应用的需求。 本文将分析AIGC的最新进展,深入探讨以上话题,以及中国算力产业的瓶颈和趋势。
vscode彻底删除安装过的插件和个人配置信息
vscode彻底删除安装过的插件和个人配置信息
2662 0
vscode彻底删除安装过的插件和个人配置信息
|
运维 关系型数据库 数据库
如何在阿里云快速启动Stable Diffusion轻松玩转AI绘画
阿里云计算巢提供了Stable Diffusion快速部署及下载自定义模型功能,使用者不需要自己下载代码,不需要自己安装复杂的依赖,不需要了解Git、Python、Docker等技术,只需要在控制台图形界面点击几下鼠标就可以快速启动Stable Diffusion服务进行绘画,非技术同学也能轻松搞定。
5994 9
如何在阿里云快速启动Stable Diffusion轻松玩转AI绘画
|
弹性计算 大数据 测试技术
2024年阿里云服务器价格表来了,最低61元一年起!
2024年阿里云服务器价格表来了,最低61元一年起!云服务器ECS经济型e实例2核2G、3M固定带宽99元一年、ECS u1实例2核4G、5M固定带宽、80G ESSD Entry盘优惠价格199元一年,轻量应用服务器2核2G3M带宽轻量服务器一年61元、2核4G4M带宽轻量服务器一年165元12个月、2核4G服务器30元3个月,幻兽帕鲁4核16G和8核32G服务器配置,云服务器ECS可以选择经济型e实例