Search

Chapter 5. Building functions

download PDF

To run a function, you first must build the function project. This happens automatically when using the kn func run command, but you can also build a function without running it.

5.1. Building a function

Before you can run a function, you must build the function project. If you are using the kn func run command, the function is built automatically. However, you can use the kn func build command to build a function without running it, which can be useful for advanced users or debugging scenarios.

The kn func build command creates an OCI container image that can be run locally on your computer or on an OpenShift Container Platform cluster. This command uses the function project name and the image registry name to construct a fully qualified image name for your function.

5.1.1. Image container types

By default, kn func build creates a container image by using Red Hat Source-to-Image (S2I) technology.

Example build command using Red Hat Source-to-Image (S2I)

$ kn func build

5.1.2. Image registry types

The OpenShift Container Registry is used by default as the image registry for storing function images.

Example build command using OpenShift Container Registry

$ kn func build

Example output

Building function image
Function image has been built, image: registry.redhat.io/example/example-function:latest

You can override using OpenShift Container Registry as the default image registry by using the --registry flag:

Example build command overriding OpenShift Container Registry to use quay.io

$ kn func build --registry quay.io/username

Example output

Building function image
Function image has been built, image: quay.io/username/example-function:latest

5.1.3. Push flag

You can add the --push flag to a kn func build command to automatically push the function image after it is successfully built:

Example build command using OpenShift Container Registry

$ kn func build --push

5.1.4. Help command

You can use the help command to learn more about kn func build command options:

Build help command

$ kn func help build

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.