DEV Community

Cover image for kn cli
Ashok Nagaraj
Ashok Nagaraj

Posted on

kn cli

The kn CLI is a command-line interface for creating and managing Knative resources
Some examples of what you can do with the kn CLI are:

  • Create, update, list, describe and delete Knative services
  • Manage traffic splitting for different service revisions
  • Create, list and delete event sources and triggers

Main advantages of using kn cli

  • Eleminates the need to create or modify YAML files directly (they can be referred later with kubectl commands) and
  • Helps simplify complex procedures such as autoscaling and traffic splitting.

The commands follow kn <object> <operation> [<options> ..] syntax

Common commands

Serving
Image description
Image credit: kn cli talk at KnativeCon

  • kn service create to create a Knative service
  • kn service update to update a Knative service
  • kn service list to list Knative services
  • kn service describe to describe a Knative service
  • kn service delete to delete a Knative service Similarly for revision, route, domain and container

Eventing
Image description
Image credit: kn cli talk at KnativeCon

Sources are objects that generate events from external systems and send them to a sink

  • Use kn source list-types to view available event source types on your cluster
  • Use kn source create to create an event source with a sink
  • Use kn source list to list event sources on your cluster Triggers are objects that filter events based on attributes and deliver them to a sink
  • kn trigger create to create a trigger with a filter and a sink
  • kn trigger update to update a trigger's filter or sink ...etc Channels are objects that provide an event delivery mechanism that can fan out events to multiple destinations
  • kn channel create to create a channel of a specified type
  • kn channel list to list channels on your cluster ..etc Similarly for subscription and eventtype

*Sinks are objects that can receive incoming events from other resources. They can be Knative services, channels, or brokers and has no direct kn cli commands

Functions

  • To create a function project interactively, run kn func create.
  • To build a function into a container image, run kn func build.
  • To run a function locally, run kn func run.
  • To deploy a function to a Knative cluster, run kn func deploy.
  • To invoke a function locally, run kn func invoke. You can find more examples and documentation on the GitHub repository of Knative Functions.
kn cli plugins

Kn cli plugins are extensions that enable you to add custom commands and functionality to your kn installation. Kn cli plugins are used in the same way as the main kn functionality.
To install a plugin, you need to download the binary for your system, rename it to start with kn-, make it executable and move it to a directory on your PATH³. You can verify that the plugin is working by running kn <plugin>.

Some examples of kn cli plugins are:

  • kn-func: A plugin for managing Knative Functions.
  • kn-hello: A "Hello World" plugin that serves as a blueprint for new plugins.
  • kn-source-kafka: A plugin for managing Kafka event sources. You can find more plugins on the Knative Sandbox repository³.

References

Top comments (0)