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

目录
相关文章
|
SQL 关系型数据库 MySQL
六、SQL多表查询
六、SQL多表查询
689 0
|
12月前
|
存储 弹性计算 人工智能
阿里云服务器 ECS 规格族解析:CPU 型号差异与性能参数对比
在阿里云 ECS 实例选型中,“规格族” 是决定性能、成本与适用场景的核心要素。许多用户会疑惑:相同 vCPU 与内存配置下,不同规格族为何价格差异显著?CPU 型号和主频究竟有何区别?本文结合阿里云今年最新实例迭代信息(如第九代 Intel 实例、AMD Turin 架构实例),从规格族定义、CPU 差异、性能参数对比三大维度展开解析,帮助用户精准匹配业务需求。
|
人工智能 测试技术 Python
AI也有“智商”吗?我们到底该用什么标准来评估它?
AI也有“智商”吗?我们到底该用什么标准来评估它?
1676 8
|
文字识别 算法 数据可视化
2025 年度机器视觉公司有哪些:从技术实力到落地案例的全方位选型参考
在智能制造背景下,机器视觉成为提质增效关键。本文发布2025年度机器视觉公司评估,从技术、场景、服务三大维度解析领先企业方案,聚焦苏州德创测控等代表,涵盖核心技术、落地案例与产教融合,为制造企业选型提供权威参考,助力智能升级。
|
安全 Linux 编译器
BigCloud Enterprise Linux 8和Rocky Linux 8升级OpenSSH步骤
本文介绍了在BigCloud Enterprise Linux 8.2/8.6和Rocky Linux 8.10上升级OpenSSH的详细步骤。首先配置Telnet服务和GCC编译器以确保远程登录安全,接着备份旧版OpenSSH并下载、编译、安装最新版本(如9.9p1)。然后创建新的sshd系统服务配置文件,调整配置并启动服务。最后验证升级效果,关闭不必要的Telnet服务,并处理可能的防火墙和SELinux问题。通过这些步骤可有效修复低版本OpenSSH带来的高危漏洞。
1317 13
|
12月前
|
SQL 大数据 数据挖掘
十、HQL:排序、联合与 CTE 高级查询
Hive 查询不仅能查,还能查得漂亮、高效。我们这次聚焦 HQL 中的高级技巧——从 ORDER BY 到 SORT BY、DISTRIBUTE BY 与 CLUSTER BY,带你理解排序在分布式环境中的执行逻辑;再深入讲解 UNION 与 CTE 等查询组织方式,帮你将复杂 SQL 拆解得更清晰。我还特意写了丰富示例与实战练习,适合正在提升 Hive 查询能力的你阅读、收藏和练习。
692 6
|
Ubuntu Unix Linux
玩机强化技能,动手安装Ubuntu Linux操作系统
(13)Ubuntu重启过程中,你将在关机画面中看到提示文字“Please remove the installation medium, then press ENTER:”,按下“Enter”键即可重启电脑。
|
JSON 缓存 JavaScript
使用 jsDelivr 免费加速 GitHub Pages 博客的静态资源(二)
使用 jsDelivr 加速 GitHub Pages 的图片资源和动态编译的 JSON 资源。
592 2
|
网络协议 算法 安全
【网络协议基础】TCP/IP协议大全
TCP/IP协议是现代计算机网络通信的基础,是互联网及局域网广泛使用的一套协议。TCP/IP协议集采用分层模型,以便于网络的设计、实现和管理。
2153 2
|
机器学习/深度学习 人工智能 供应链
工业互联网平台
工业互联网平台
1640 3