The Knative CLI (kn) does not have its own login mechanism. To log in to the cluster, you must install the oc CLI and use the oc login command.

Installation options for the oc CLI will vary depending on your operating system.

For more information on installing the oc CLI for your operating system and logging in with oc, see the OpenShift CLI getting started documentation.

If you try to use an older version of the Knative kn CLI with a newer OpenShift Serverless release, the API is not found and an error occurs.

For example, if you use the 1.16.0 release of the kn CLI, which uses version 0.22.0, with the 1.17.0 OpenShift Serverless release, which uses the 0.23.0 versions of the Knative Serving and Knative Eventing APIs, the CLI does not work because it continues to look for the outdated 0.22.0 API versions.

Ensure that you are using the latest kn CLI version for your OpenShift Serverless release to avoid issues.

Installing the Knative CLI using the OpenShift Container Platform web console

Once the OpenShift Serverless Operator is installed, you will see a link to download the Knative CLI (kn) for Linux (x86_64, amd64, s390x, ppc64le), macOS, or Windows from the Command Line Tools page in the OpenShift Container Platform web console.

You can access the Command Line Tools page by clicking the question circle icon in the top right corner of the web console and selecting Command Line Tools in the drop down menu.

Procedure
  1. Download the kn CLI from the Command Line Tools page.

  2. Unpack the archive:

    $ tar -xf <file>
  3. Move the kn binary to a directory on your PATH.

  4. To check your PATH, run:

    $ echo $PATH

    If you do not use RHEL or Fedora, ensure that libc is installed in a directory on your library path. If libc is not available, you might see the following error when you run CLI commands:

    $ kn: No such file or directory

Installing the Knative CLI for Linux using an RPM

For Red Hat Enterprise Linux (RHEL), you can install the Knative CLI (kn) as an RPM if you have an active OpenShift Container Platform subscription on your Red Hat account.

Procedure
  1. Enter the command:

    # subscription-manager register
  2. Enter the command:

    # subscription-manager refresh
  3. Enter the command:

    # subscription-manager attach --pool=<pool_id> (1)
    1 Pool ID for an active OpenShift Container Platform subscription
  4. Enter the command:

    # subscription-manager repos --enable="openshift-serverless-1-for-rhel-8-x86_64-rpms"
  5. Enter the command:

    # yum install openshift-serverless-clients

Installing the Knative CLI for Linux

For Linux distributions, you can download the Knative CLI (kn) directly as a tar.gz archive.

Procedure
  1. Download the kn CLI.

  2. Unpack the archive:

    $ tar -xf <file>
  3. Move the kn binary to a directory on your PATH.

  4. To check your PATH, run:

    $ echo $PATH

    If you do not use RHEL or Fedora, ensure that libc is installed in a directory on your library path. If libc is not available, you might see the following error when you run CLI commands:

    $ kn: No such file or directory

Installing the Knative CLI for Linux on IBM Power Systems using an RPM

For Red Hat Enterprise Linux (RHEL), you can install the Knative CLI (kn) as an RPM if you have an active OpenShift Container Platform subscription on your Red Hat account.

Procedure
  1. Register with a Red Hat Subscription Management (RHSM) service during the firstboot process:

    # subscription-manager register
  2. Refresh the RHSM:

    # subscription-manager refresh
  3. Attach the subscription to a system by specifying ID of the subscription pool, using the --pool option:

    # subscription-manager attach --pool=<pool_id> (1)
    1 Pool ID for an active OpenShift Container Platform subscription
  4. Enable the repository using Red Hat Subscription Manager:

    # subscription-manager repos --enable="openshift-serverless-1-for-rhel-8-ppc64le-rpms"
  5. Install the openshift-serverless-clients on the system:

    # yum install openshift-serverless-clients

Installing the Knative CLI for Linux on IBM Power Systems

For Linux distributions, you can download the Knative CLI (kn) directly as a tar.gz archive.

Procedure
  1. Download the kn CLI.

  2. Unpack the archive:

    $ tar -xf <file>
  3. Move the kn binary to a directory on your PATH.

  4. To check your PATH, run:

    $ echo $PATH

    If you do not use RHEL, ensure that libc is installed in a directory on your library path.

    If libc is not available, you might see the following error when you run CLI commands:

    $ kn: No such file or directory

Installing the Knative CLI for Linux on IBM Z and LinuxONE using an RPM

For Red Hat Enterprise Linux (RHEL), you can install the Knative CLI (kn) as an RPM if you have an active OpenShift Container Platform subscription on your Red Hat account.

Procedure
  1. Register with a Red Hat Subscription Management (RHSM) service during the firstboot process:

    # subscription-manager register
  2. Refresh the RHSM:

    # subscription-manager refresh
  3. Attach the subscription to a system by specifying ID of the subscription pool, using the --pool option:

    # subscription-manager attach --pool=<pool_id> (1)
    1 Pool ID for an active OpenShift Container Platform subscription
  4. Enable the repository using Red Hat Subscription Manager:

    # subscription-manager repos --enable="openshift-serverless-1-for-rhel-8-s390x-rpms"
  5. Install the openshift-serverless-clients on the system:

    # yum install openshift-serverless-clients

Installing the Knative CLI for Linux on IBM Z and LinuxONE

For Linux distributions, you can download the Knative CLI (kn) directly as a tar.gz archive.

Procedure
  1. Download the kn CLI.

  2. Unpack the archive:

    $ tar -xf <file>
  3. Move the kn binary to a directory on your PATH.

  4. To check your PATH, run:

    $ echo $PATH

    If you do not use RHEL, ensure that libc is installed in a directory on your library path.

    If libc is not available, you might see the following error when you run CLI commands:

    $ kn: No such file or directory

Installing the Knative CLI for macOS

The Knative CLI (kn) for macOS is provided as a tar.gz archive.

Procedure
  1. Download the kn CLI.

  2. Unpack and unzip the archive.

  3. Move the kn binary to a directory on your PATH.

  4. To check your PATH, open a terminal window and run:

    $ echo $PATH

Installing the Knative CLI for Windows

The Knative CLI (kn) for Windows is provided as a zip archive.

Procedure
  1. Download the kn CLI.

  2. Extract the archive with a ZIP program.

  3. Move the kn binary to a directory on your PATH.

  4. To check your PATH, open the command prompt and run the command:

    C:\> path

Customizing the Knative CLI

You can customize your kn CLI setup by creating a config.yaml configuration file. You can provide this configuration by using the --config flag, otherwise the configuration is picked up from a default location. The default configuration location conforms to the XDG Base Directory Specification, and is different for Unix systems and Windows systems.

For Unix systems:

  • If the XDG_CONFIG_HOME environment variable is set, the default configuration location that the kn CLI looks for is $XDG_CONFIG_HOME/kn.

  • If the XDG_CONFIG_HOME environment variable is not set, the kn CLI looks for the configuration in the home directory of the user at $HOME/.config/kn/config.yaml.

For Windows systems, the default kn CLI configuration location is %APPDATA%\kn.

Example configuration file
plugins:
  path-lookup: true (1)
  directory: ~/.config/kn/plugins (2)
eventing:
  sink-mappings: (3)
  - prefix: svc (4)
    group: core (5)
    version: v1 (6)
    resource: services (7)
1 Specifies whether the kn CLI should look for plug-ins in the PATH environment variable. This is a boolean configuration option. The default value is false.
2 Specifies the directory where the kn CLI will look for plug-ins. The default path depends on the operating system, as described above. This can be any directory that is visible to the user.
3 The sink-mappings spec defines the Kubernetes addressable resource that is used when you use the --sink flag with a kn CLI command.
4 The prefix you want to use to describe your sink. svc for a service, channel, and broker are predefined prefixes in kn.
5 The API group of the Kubernetes resource.
6 The version of the Kubernetes resource.
7 The plural name of the Kubernetes resource type. For example, services or brokers.

Knative CLI plug-ins

The kn CLI supports the use of plug-ins, which enable you to extend the functionality of your kn installation by adding custom commands and other shared commands that are not part of the core distribution. kn CLI plug-ins are used in the same way as the main kn functionality.

Currently, Red Hat supports the kn-source-kafka plug-in.