Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

Chapter 2. Creating functions


Before you can build and deploy a function, you must create it. You can create functions using the Knative (kn) CLI.

2.1. Creating a function by using the Knative CLI

You can specify the path, runtime, template, and image registry for a function as flags on the command line, or use the -c flag to start the interactive experience in the terminal.

Prerequisites

  • You have installed the OpenShift Serverless Operator and Knative Serving on the cluster.
  • You have installed the Knative (kn) CLI.

Procedure

  1. Create a function project:

    $ kn func create -r <repository> -l <runtime> -t <template> <path>
    • Accepted runtime values include quarkus, node, typescript, go, python, springboot, and rust.
    • Accepted template values include http and cloudevents.

      You get an output similar to the following example:

      $ kn func create -l typescript -t cloudevents examplefunc

      You get an output similar to the following example:

      Created typescript function in /home/user/demo/examplefunc
  2. Specify a repository that has a custom template.

    You get an output similar to the following example:

    $ $ kn func create -r <templates_repository> -l node -t hello-world examplefunc

    Replace <templates_repository> with the repository that has the function templates.

    You get an output similar to the following example:

    Created node function in /home/user/demo/examplefunc

2.2. Creating a function in the web console

You can create a function from a Git repository by using the OpenShift Container Platform web console.

Prerequisites

  • Before you can create a function by using the web console, a cluster administrator must complete the following steps:

    • Install the OpenShift Serverless Operator and Knative Serving on the cluster.
    • Install the OpenShift Pipelines Operator on the cluster.
    • Create the following pipeline tasks so that they are available for all namespaces on the cluster:

      func-s2i and func-deploy tasks

      $ kn func tkn-tasks | oc apply -f -

      Node.js function

      $ oc apply -f https://raw.githubusercontent.com/openshift-knative/kn-plugin-func/serverless-1.34/pkg/pipelines/resources/tekton/pipeline/dev-console/0.1/nodejs-pipeline.yaml

  • You must log in to the OpenShift Container Platform web console.
  • You must create a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in OpenShift Container Platform.
  • You must create or have access to a Git repository that has the code for your function. The repository must contain a func.yaml file and use the s2i build strategy.

Procedure

  1. Navigate to +Add Create Serverless function. The Create Serverless function page is displayed.
  2. Enter a Git Repo URL that points to the Git repository that has the code for your function.
  3. In the Pipelines section:

    1. Select the Build, deploy and configure a Pipeline Repository radio button to create a new pipeline for your function.
    2. Select the Use Pipeline from this cluster radio button to connect your function to an existing pipeline in the cluster.
  4. Click Create.

Verification

  • After you have created a function, you can view it in the Topology view.
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2026 Red Hat
Nach oben