Quick start

The procedures in this quick start guide demonstrate how you can create, deploy, and modify functions.

Prerequisites

Before you can complete the steps in the following procedures, you must ensure that:

  • You have access to an OpenShift Container Platform cluster, which has the OpenShift Serverless Operator, Knative Serving and Knative Eventing installed.

  • You have installed the OpenShift oc CLI.

  • You have installed Docker, and have access to a publicly available image registry.

    If you are using quay.io as the image registry, you must ensure that the repository is not private. The first time an image is deployed these settings may need to be updated.

  • You have installed the Knative kn CLI. Installing kn provides the binary that enables use of the kn func commands. There is no additional setup required to use kn func commands after kn is successfully installed.

Creating functions

You can create a function by using the kn func create command.

Example command
$ kn func create <path> -r <registry> -l <runtime> -t <trigger> -i <image> -n <namespace> -c

You can specify the runtime, trigger, image, and namespace as flags on the command line, or use the -c flag to start the interactive experience using the CLI prompt.

The value(s) provided for image and registry are persisted to the func.yaml file, so that subsequent invocations do not require the user to specify these again.

Example func.yaml
name: fn.example.io
namespace: default
runtime: node
image: <image_from_registry>
imageDigest: ""
trigger: http
builder: default
builderMap:
  default: quay.io/boson/faas-nodejs-builder
envVars: {}
Procedure
  • Create a Functions project:

    $ kn func create <path> -r <registry> -l <runtime> -t <trigger> -i <image> -n <namespace>

    If the image is unspecified, you will be prompted for a registry name. The image name will be derived from this registry and the function name.

    Example command
    $ kn func create functions/fn.example.io
    Example output
    Project path: /home/user/functions/fn.example.io
    Function name: fn.example.io
    Runtime: go
    Trigger: http

Building a function

You can build a function project by using the kn func build command.

The build command reads the func.yaml file in the directory for your function to determine the image name and registry.

Example func.yaml
name: fn.example.io
namespace: default
runtime: node
image: <image_from_registry>
imageDigest: ""
trigger: http
builder: default
builderMap:
  default: quay.io/boson/faas-nodejs-builder
envVars: {}

If both of these values are unset, you will be prompted to provide a registry. An image name is then be derived from the registry.

The value(s) provided for image and registry are persisted to the func.yaml file, so that subsequent invocations do not require the user to specify these again.

Procedure
  • Build a function:

    $ kn func build [-i <image> -r <registry> -p <path>]

Deploying a function

You can deploy a function to your cluster as a Knative service, by using the kn func deploy command.

If the targeted function is already deployed, it is updated with a new container image that is pushed to a container image registry, and the Knative service is updated.

If you are using quay.io as the image registry, you must ensure that the repository is not private. The first time an image is deployed these settings may need to be updated.

Prerequisites
  • You must have already initialized the function that you want to deploy.

Procedure
  • Deploy a function:

    $ kn func deploy [-n <namespace> -p <path> -i <image> -r <registry>]
    • If no namespace is specified, the function will be deployed in the current namespace.

    • The function is deployed from the current directory, unless a path is specified.

    • The Knative service name is derived from the project name, and cannot be changed using this command.

Deleting a function

You can delete a function from your cluster by using the kn func delete command.

Procedure
  • Delete a function:

    $ kn func delete <name> [-n <namespace> -p <path>]
    • If the name or path of the function to delete is not specified, the current directory is searched for a func.yaml file that can be used to determine the function to delete.

    • If the namespace is not specified, this defaults to the namespace value in the func.yaml file.

Additional resources

  • For more information about optional flags that can be set when creating a Functions project, see the CLI reference guide.

  • For information about using functions as part of an event-driven workflow, see Event workflows.