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
kubectlcommands) and - Helps simplify complex procedures such as autoscaling and traffic splitting.
The commands follow kn <object> <operation> [<options> ..] syntax
Common commands
Serving

Image credit: kn cli talk at KnativeCon
-
kn service createto create a Knative service -
kn service updateto update a Knative service -
kn service listto list Knative services -
kn service describeto describe a Knative service -
kn service deleteto delete a Knative service Similarly forrevision,route,domainandcontainer
Eventing

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-typesto view available event source types on your cluster - Use
kn source createto create an event source with a sink - Use
kn source listto list event sources on your cluster Triggers are objects that filter events based on attributes and deliver them to a sink -
kn trigger createto create a trigger with a filter and a sink -
kn trigger updateto 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 createto create a channel of a specified type -
kn channel listto list channels on your cluster ..etc Similarly forsubscriptionandeventtype
*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)