Building and deploying functions on the cluster
-
Red Hat OpenShift Pipelines must be installed on your cluster.
-
You have installed the OpenShift CLI (
oc). -
You have installed the Knative (
kn) CLI.
-
In each namespace where you want to run Pipelines and deploy a function, you must create the following resources:
-
Create the functions buildpacks Tekton task to be able to build the function image:
$ oc apply -f https://raw.githubusercontent.com/openshift-knative/kn-plugin-func/serverless-1.22.0/pipelines/resources/tekton/task/func-buildpacks/0.1/func-buildpacks.yaml -
Create the
kn funcdeploy Tekton task to be able to deploy the function in the pipeline:$ oc apply -f https://raw.githubusercontent.com/openshift-knative/kn-plugin-func/serverless-1.22.0/pipelines/resources/tekton/task/func-deploy/0.1/func-deploy.yaml
-
-
Create a function:
$ kn func create <function_name> -l <runtime> -
After you have created a new function project, you must add the project to a Git repository and ensure that the repository is available to the cluster. Information about this Git repository is used to update the
func.yamlfile in the next step. -
Update the configuration in the
func.yamlfile for your function project to enable on-cluster builds for the Git repository:... build: git (1) git: url: <git_repository_url> (2) revision: main (3) contextDir: <directory_path> (4) ...1 Required. Specify gitbuild type.2 Required. Specify the Git repository that contains your function’s source code. 3 Optional. Specify the Git repository revision to be used. This can be a branch, tag or commit. 4 Optional. Specify the function’s directory path if the function is not located in the Git repository root folder. -
Implement the business logic of your function. Then, use Git to commit and push the changes.
-
Deploy your function:
$ kn func deploy --remoteIf you are not logged into the container registry referenced in your function configuration, you are prompted to provide credentials for the remote container registry that hosts the function image:
Example output and prompts🕕 Creating Pipeline resources Please provide credentials for image registry used by Pipeline. ? Server: https://index.docker.io/v1/ ? Username: my-repo ? Password: ******** Function deployed at URL: http://test-function.default.svc.cluster.local -
To update your function, commit and push new changes by using Git, then run the
kn func deploy --remotecommand again.