Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

OpenShift Lab 14: Setting Up and Using OpenShift Serverless Functions on OpenShift Local

Lab Objective

In this lab, you will install and use OpenShift Serverless Functions on OpenShift Local.

You will create a simple Node.js serverless function, deploy it to OpenShift, invoke it using HTTP, verify the Knative resources created by OpenShift Serverless, and observe scale-to-zero behavior.

This lab is a modern replacement for the older โ€œSetting up and using OpenShift Serverless Functionsโ€ article. The original article explains the concept, but this replacement provides a complete hands-on lab for students.


What You Will Learn

You will learn how to:

  1. Start OpenShift Local.
  2. Log in as both developer and kubeadmin.
  3. Install the OpenShift Serverless Operator.
  4. Install Knative Serving.
  5. Install and validate the Knative kn CLI.
  6. Prepare an image registry for function images.
  7. Create a new project for functions.
  8. Create a Node.js function using kn func.
  9. Modify the function code.
  10. Deploy the function as a Knative Service.
  11. Invoke the function.
  12. Validate Knative Service, Revision, Configuration, and Route resources.
  13. Observe scale-to-zero and scale-from-zero.
  14. View function logs.
  15. Troubleshoot common OpenShift Serverless issues.
  16. Clean up the lab environment.

Lab Architecture

Developer Machine
  |
  | kn func create
  | kn func deploy
  | kn func invoke
  v
OpenShift Local
  |
  v
OpenShift Serverless Operator
  |
  v
Knative Serving
  |
  v
Knative Service
  |
  v
Revision
  |
  v
Pod
  |
  v
Knative Route
  |
  v
Function URL
Code language: JavaScript (javascript)

What Is OpenShift Serverless?

OpenShift Serverless allows you to run applications and functions that automatically scale based on demand.

It is based on Knative.

In simple terms:

Normal Deployment:
Application pod usually keeps running.

Serverless Function:
Function pod starts when traffic arrives.
Function pod can scale down to zero when idle.
Code language: JavaScript (javascript)

What Is a Serverless Function?

A serverless function is a small piece of code that runs in response to a request or event.

Examples:

HTTP request
CloudEvent
Message from a queue
Kafka event
Webhook event
Code language: JavaScript (javascript)

In this beginner lab, you will use a simple HTTP function.


Important Concept: Function vs Deployment

AreaNormal OpenShift DeploymentOpenShift Serverless Function
Main resourceDeploymentKnative Service
ScalingManual, HPA, or custom autoscalingAutomatic request-based scaling
Scale to zeroNot by defaultYes
Route handlingOpenShift RouteKnative Route
Build/deploy tooloc, Git, pipelines, image deploykn func
Good forLong-running appsEvent-driven or request-driven workloads

Important Concept: Function vs Knative Service

A function is a developer workflow.

A Knative Service is the runtime resource created after the function is deployed.

Function source code
  -> container image
  -> Knative Service
  -> Revision
  -> Pod
  -> URL
Code language: JavaScript (javascript)

When you run:

kn func deploy

OpenShift packages your function into a container image and deploys it as a Knative Service.


Important Lab Note: Admin and Student Responsibilities

This lab has two parts.

PartWho Runs ItPurpose
Admin setupInstructor or cluster adminInstall OpenShift Serverless Operator and Knative Serving
Student labDeveloper userCreate, deploy, invoke, and observe a function

A normal developer user cannot install cluster operators. The operator setup must be done by kubeadmin or another cluster administrator.


Part 1: Prerequisites

Required Software

You need:

  1. OpenShift Local installed.
  2. crc command available.
  3. oc command available.
  4. kn CLI installed.
  5. Podman or Docker installed.
  6. Browser access to OpenShift web console.
  7. Internet access from OpenShift Local.
  8. Red Hat pull secret configured for OpenShift Local.
  9. Enough CPU and memory for Serverless components.

Recommended OpenShift Local Resources

OpenShift Serverless needs more resources than a simple Deployment lab.

Recommended OpenShift Local configuration:

ResourceRecommended
CPU6 cores
Memory16 GB
Disk50 GB

Configure CRC before starting the cluster:

crc config set preset openshift
crc config set cpus 6
crc config set memory 16384
crc config set disk-size 50
Code language: JavaScript (javascript)

If CRC is already running, stop it first:

crc stop

Then start again after changing resources.


Part 2: Start OpenShift Local

Run:

crc version

Run setup:

crc setup

Start OpenShift Local:

crc start

View credentials:

crc console --credentials
Code language: JavaScript (javascript)

Open the console:

crc console
Code language: JavaScript (javascript)

Part 3: Configure the oc CLI

Run:

crc oc-env

On Linux or macOS:

eval $(crc oc-env)
Code language: JavaScript (javascript)

On Windows PowerShell, use the command printed by crc oc-env.

Log in as developer first:

oc login -u developer https://api.crc.testing:6443
Code language: JavaScript (javascript)

Verify:

oc whoami

Expected output:

developer

Now log in as kubeadmin for the admin setup section:

oc login -u kubeadmin https://api.crc.testing:6443
Code language: JavaScript (javascript)

Use the kubeadmin password from:

crc console --credentials
Code language: JavaScript (javascript)

Verify:

oc whoami

Expected output:

kubeadmin

Check the node:

oc get nodes
Code language: JavaScript (javascript)

Expected result:

crc-xxxxx-master-0   Ready

Part 4: Install the OpenShift Serverless Operator

This section must be done by kubeadmin or a cluster administrator.

You can install the Operator from the web console or CLI.


Option A: Install from the Web Console

  1. Log in to the OpenShift web console as kubeadmin.
  2. Switch to Administrator perspective.
  3. Go to Operators > OperatorHub.
  4. Search for:
OpenShift Serverless Operator
  1. Click the Operator.
  2. Click Install.
  3. Use these settings:
SettingValue
Installation modeAll namespaces on the cluster
Installed namespaceopenshift-serverless
Update channelstable
Approval strategyAutomatic
  1. Click Install.
  2. Wait until the Operator status shows:
Succeeded

Option B: Install from CLI

Create the Operator subscription YAML:

cat <<'EOF' > serverless-operator.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: openshift-serverless
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
  name: serverless-operators
  namespace: openshift-serverless
spec: {}
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: serverless-operator
  namespace: openshift-serverless
spec:
  channel: stable
  installPlanApproval: Automatic
  name: serverless-operator
  source: redhat-operators
  sourceNamespace: openshift-marketplace
EOF
Code language: JavaScript (javascript)

Apply it:

oc apply -f serverless-operator.yaml
Code language: CSS (css)

Watch the installation:

oc get pods -n openshift-serverless
Code language: JavaScript (javascript)

Check ClusterServiceVersion status:

oc get csv -n openshift-serverless
Code language: JavaScript (javascript)

Wait until the CSV phase is:

Succeeded

You can watch it with:

watch oc get csv -n openshift-serverless
Code language: JavaScript (javascript)

If watch is not available, run this repeatedly:

oc get csv -n openshift-serverless
Code language: JavaScript (javascript)

Part 5: Install Knative Serving

OpenShift Serverless Operator alone is not enough. To run functions, you must install Knative Serving.

Knative Serving allows you to create Knative Services and serverless functions.


Option A: Install Knative Serving from Web Console

  1. Log in as kubeadmin.
  2. Switch to Administrator perspective.
  3. Go to Operators > Installed Operators.
  4. Select project:
knative-serving

If the project does not exist yet, create it from Home > Projects > Create Project.

  1. Click OpenShift Serverless Operator.
  2. Find Knative Serving under provided APIs.
  3. Click Create Knative Serving.
  4. Keep the default settings.
  5. Click Create.

Wait until the KnativeServing resource is ready.


Option B: Install Knative Serving from CLI

Create the knative-serving namespace and KnativeServing resource:

cat <<'EOF' > knative-serving.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: knative-serving
---
apiVersion: operator.knative.dev/v1beta1
kind: KnativeServing
metadata:
  name: knative-serving
  namespace: knative-serving
EOF
Code language: JavaScript (javascript)

Apply it:

oc apply -f knative-serving.yaml
Code language: CSS (css)

Verify the custom resource:

oc get knativeserving.operator.knative.dev knative-serving -n knative-serving
Code language: CSS (css)

Check Knative Serving conditions:

oc get knativeserving.operator.knative.dev knative-serving -n knative-serving \
  --template='{{range .status.conditions}}{{printf "%s=%s\n" .type .status}}{{end}}'
Code language: PHP (php)

Expected result should show conditions with:

True
Code language: PHP (php)

Check pods:

oc get pods -n knative-serving
Code language: JavaScript (javascript)

You should see Knative Serving pods running.

Example components may include:

activator
autoscaler
controller
webhook

The exact pod names can vary by OpenShift Serverless version.


Part 6: Validate Serverless Installation

Run:

oc api-resources | grep -i knative

Check for Knative Service API:

oc api-resources | grep ksvc

Expected result should include:

services   ksvc   serving.knative.dev
Code language: CSS (css)

Check Knative Serving namespace:

oc get pods -n knative-serving
Code language: JavaScript (javascript)

Check OpenShift Serverless namespace:

oc get pods -n openshift-serverless
Code language: JavaScript (javascript)

If the Operator and Knative Serving pods are running, the platform setup is ready.


Part 7: Install and Validate the kn CLI

The kn CLI is the Knative command-line tool.

It is required for the kn func workflow.

Install from Web Console

  1. Open the OpenShift web console.
  2. Click the ? icon in the upper-right corner.
  3. Click Command Line Tools.
  4. Download the Knative CLI for your operating system.
  5. Extract the archive.
  6. Move the kn binary into a directory on your PATH.

On Linux or macOS, a typical location is:

/usr/local/bin

On Windows, put kn.exe in a folder included in your PATH.


Validate kn

Run:

kn version

Check that the function commands are available:

kn func --help

Expected result:

Available Commands:
  build
  create
  deploy
  invoke
  run
  delete
Code language: JavaScript (javascript)

The exact output may vary, but kn func should be recognized.


Part 8: Validate Podman or Docker

OpenShift Serverless Functions need a local container engine to build function images.

Podman is recommended for this lab.

Check Podman:

podman version

If you use Docker instead:

docker version

For macOS or Windows with Podman, make sure the Podman machine is running:

podman machine list
podman machine start
Code language: PHP (php)

If Podman or Docker is not working, kn func deploy will fail during the build step.


Part 9: Prepare an Image Registry

When you deploy a function, the function image must be pushed to a container image registry.

You have two options:

OptionBest For
OpenShift internal registryLocal OpenShift lab
Quay.io or another external registryReal team workflow or if internal registry is difficult

For OpenShift Local classroom labs, use the OpenShift internal registry.


Option A: Use OpenShift Internal Registry

Log in as kubeadmin:

oc login -u kubeadmin https://api.crc.testing:6443
Code language: JavaScript (javascript)

Expose the default OpenShift image registry route:

oc patch configs.imageregistry.operator.openshift.io/cluster \
  --type=merge \
  -p '{"spec":{"defaultRoute":true}}'
Code language: JavaScript (javascript)

Wait for the default registry route:

oc get route default-route -n openshift-image-registry
Code language: JavaScript (javascript)

Save the registry hostname:

REGISTRY_HOST=$(oc get route default-route -n openshift-image-registry -o jsonpath='{.spec.host}')
echo "$REGISTRY_HOST"
Code language: PHP (php)

Log in to the registry with Podman:

podman login --tls-verify=false \
  -u "$(oc whoami)" \
  -p "$(oc whoami -t)" \
  "$REGISTRY_HOST"
Code language: JavaScript (javascript)

If login succeeds, you are ready to push function images to the internal registry.


Option B: Use Quay.io

Use this option only if the OpenShift internal registry route does not work in your local environment.

Log in to Quay.io:

podman login quay.io
Code language: CSS (css)

When deploying the function later, use an image name such as:

quay.io/<your-quay-username>/lab14-hello-func:latest
Code language: HTML, XML (xml)

Replace <your-quay-username> with your actual Quay username.


Part 10: Create a Student Project

Log in as developer:

oc login -u developer https://api.crc.testing:6443
Code language: JavaScript (javascript)

Create a new project:

oc new-project lab14-serverless-functions
Code language: JavaScript (javascript)

Verify:

oc project

Expected output:

Using project "lab14-serverless-functions"
Code language: JavaScript (javascript)

Part 11: Create a Node.js Serverless Function

Create a function:

kn func create -l node -t http lab14-hello-func

Expected output:

Created node function in lab14-hello-func
Code language: JavaScript (javascript)

Go into the function directory:

cd lab14-hello-func

List the files:

ls -la

Expected files include:

func.yaml
index.js
package.json
README.md
test
Code language: CSS (css)

Part 12: Understand the Function Project

The function project contains:

File or DirectoryPurpose
func.yamlFunction configuration
index.jsFunction source code
package.jsonNode.js dependencies and scripts
README.mdFunction documentation
test/Unit and integration tests

The most important files for this beginner lab are:

func.yaml
index.js
Code language: CSS (css)

Part 13: Replace the Function Code

Open index.js and replace the content with the following code.

cat <<'EOF' > index.js
const Function = {
  handle: (context, body) => {
    context.log.info('Lab 14 function was invoked');

    return 'Hello from OpenShift Serverless Functions - Lab 14';
  }
};

module.exports = Function;
EOF
Code language: JavaScript (javascript)

This function returns a simple text response.


Part 14: Review func.yaml

View the function configuration:

cat func.yaml
Code language: CSS (css)

You should see values such as:

name: lab14-hello-func
runtime: node
Code language: HTTP (http)

The exact content may vary depending on your kn version.

Do not manually change the file unless your instructor asks you to.


Part 15: Optional Local Run

You can run the function locally before deploying it.

This step requires Podman or Docker to work correctly.

Run:

kn func run

Open a second terminal and go into the same function directory:

cd lab14-hello-func

Invoke the local function:

kn func invoke

Expected response:

Hello from OpenShift Serverless Functions - Lab 14
Code language: JavaScript (javascript)

Stop the local function by pressing:

Ctrl + C

If local run does not work because of Podman or Docker networking, continue with cluster deployment.


Part 16: Deploy the Function to OpenShift

Make sure you are in the function directory:

pwd

Expected path should end with:

lab14-hello-func

Set the project:

oc project lab14-serverless-functions

Get the internal registry hostname if you are using the OpenShift internal registry:

REGISTRY_HOST=$(oc get route default-route -n openshift-image-registry -o jsonpath='{.spec.host}')
echo "$REGISTRY_HOST"
Code language: PHP (php)

Deploy the function:

kn func deploy -i "$REGISTRY_HOST/lab14-serverless-functions/lab14-hello-func:latest"
Code language: JavaScript (javascript)

Expected output should include:

Function deployed at:
Code language: JavaScript (javascript)

This command builds the function image, pushes it to the image registry, and deploys it as a Knative Service.


Quay.io Alternative

If you are using Quay.io instead of the OpenShift internal registry, run:

kn func deploy -i "quay.io/<your-quay-username>/lab14-hello-func:latest"
Code language: HTML, XML (xml)

Replace <your-quay-username> with your actual Quay username.


Part 17: Verify the Function Deployment

Check Knative Services:

oc get ksvc
Code language: JavaScript (javascript)

Expected output:

NAME                 URL                                      LATESTCREATED              LATESTREADY                READY
lab14-hello-func     http://lab14-hello-func-...              lab14-hello-func-00001     lab14-hello-func-00001     True
Code language: JavaScript (javascript)

Check with kn:

kn service list
Code language: PHP (php)

Expected result should include:

lab14-hello-func

Check all related Knative resources:

oc get ksvc,revision,configuration,routes.serving.knative.dev
Code language: CSS (css)

You should see resources related to:

lab14-hello-func

Part 18: Get the Function URL

Get the function URL:

FUNC_URL=$(oc get ksvc lab14-hello-func -o jsonpath='{.status.url}')
echo "$FUNC_URL"
Code language: PHP (php)

Expected output:

http://lab14-hello-func-lab14-serverless-functions.apps-crc.testing
Code language: JavaScript (javascript)

The exact hostname may be different.


Part 19: Invoke the Function

Invoke using kn func:

kn func invoke

Expected response:

Hello from OpenShift Serverless Functions - Lab 14
Code language: JavaScript (javascript)

Invoke using curl:

curl -s "$FUNC_URL"
Code language: JavaScript (javascript)

Expected response:

Hello from OpenShift Serverless Functions - Lab 14
Code language: JavaScript (javascript)

If the first request is slow, that can be normal. A scaled-to-zero function may need a few seconds to start.


Part 20: View Function Logs

Check the Knative Service:

oc get ksvc lab14-hello-func
Code language: JavaScript (javascript)

Check pods:

oc get pods
Code language: JavaScript (javascript)

View logs from the function pod:

oc logs -l serving.knative.dev/service=lab14-hello-func

Expected log message:

Lab 14 function was invoked
Code language: JavaScript (javascript)

If no pod exists because the function scaled to zero, invoke the function again:

curl -s "$FUNC_URL"
Code language: JavaScript (javascript)

Then check logs again:

oc logs -l serving.knative.dev/service=lab14-hello-func

Part 21: Observe Scale-to-Zero

Knative Serving can scale a function down to zero pods when it is idle.

Run:

oc get pods -l serving.knative.dev/service=lab14-hello-func
Code language: JavaScript (javascript)

You should see a running pod shortly after invoking the function.

Now wait for a short idle period.

Run the command again:

oc get pods -l serving.knative.dev/service=lab14-hello-func
Code language: JavaScript (javascript)

After the function has been idle, the pod may disappear.

Expected result after scale-to-zero:

No resources found

The exact time can vary based on cluster configuration.


Part 22: Observe Scale-from-Zero

Invoke the function again:

curl -s "$FUNC_URL"
Code language: JavaScript (javascript)

Expected response:

Hello from OpenShift Serverless Functions - Lab 14
Code language: JavaScript (javascript)

Immediately check pods:

oc get pods -l serving.knative.dev/service=lab14-hello-func
Code language: JavaScript (javascript)

You should see a new pod created for the function.

This proves that the function can scale from zero when traffic arrives.


Part 23: Inspect the Knative Service

Describe the Knative Service:

oc describe ksvc lab14-hello-func

Look for:

URL
LatestCreatedRevisionName
LatestReadyRevisionName
Ready
RoutesReady
ConfigurationsReady

Check the latest revision:

oc get revision
Code language: JavaScript (javascript)

Check the Knative configuration:

oc get configuration
Code language: JavaScript (javascript)

Check the Knative route:

oc get routes.serving.knative.dev
Code language: CSS (css)

These resources are created and managed by Knative Serving.


Part 24: Update the Function

Modify the function response:

cat <<'EOF' > index.js
const Function = {
  handle: (context, body) => {
    context.log.info('Lab 14 function version 2 was invoked');

    return 'Hello from OpenShift Serverless Functions - Lab 14 - Version 2';
  }
};

module.exports = Function;
EOF
Code language: JavaScript (javascript)

Deploy again:

kn func deploy -i "$REGISTRY_HOST/lab14-serverless-functions/lab14-hello-func:latest"
Code language: JavaScript (javascript)

Invoke the function:

curl -s "$FUNC_URL"
Code language: JavaScript (javascript)

Expected response:

Hello from OpenShift Serverless Functions - Lab 14 - Version 2
Code language: JavaScript (javascript)

Check revisions:

oc get revision
Code language: JavaScript (javascript)

You should see more than one revision.

This shows that updating a function creates a new Knative revision.


Part 25: Validate from the Web Console

  1. Open the OpenShift web console.
  2. Log in as developer.
  3. Select project:
lab14-serverless-functions
  1. Switch to Developer perspective.
  2. Go to Topology.
  3. You should see:
lab14-hello-func
  1. Click the function.
  2. Check the Resources tab.
  3. Check pods, revisions, and routes if shown.
  4. Open the function URL from the console if available.

The web console layout can vary by OpenShift version, but the function should be visible as a serverless workload.


Part 26: Full Student Validation Script

Run this from the function directory:

oc project lab14-serverless-functions

echo "Checking Knative Service..."
oc get ksvc lab14-hello-func

echo "Checking URL..."
FUNC_URL=$(oc get ksvc lab14-hello-func -o jsonpath='{.status.url}')
echo "$FUNC_URL"

echo "Invoking function..."
curl -s "$FUNC_URL"
echo

echo "Checking Knative resources..."
oc get ksvc,revision,configuration,routes.serving.knative.dev

echo "Checking pods..."
oc get pods -l serving.knative.dev/service=lab14-hello-func

echo "Checking logs..."
oc logs -l serving.knative.dev/service=lab14-hello-func --tail=50
Code language: PHP (php)

Expected result:

  1. Knative Service exists.
  2. Function URL exists.
  3. Function returns a response.
  4. Revision exists.
  5. Configuration exists.
  6. Knative Route exists.
  7. Pod exists after invocation.
  8. Logs show invocation output.

Part 27: Troubleshooting

Problem 1: kn: command not found

Cause

The Knative CLI is not installed or not in your PATH.

Fix

Download kn from:

OpenShift web console > ? > Command Line Tools
Code language: JavaScript (javascript)

Move the binary to a directory in your PATH.

Verify:

kn version

Problem 2: kn func Is Not Recognized

Cause

You may have an older or incorrect kn binary.

Fix

Install the kn CLI version provided by your OpenShift Serverless installation.

Check:

kn func --help

If this fails, reinstall the CLI from the OpenShift web console Command Line Tools page.


Problem 3: OpenShift Serverless Operator Is Not Installed

Symptom

oc get pods -n openshift-serverless
Code language: JavaScript (javascript)

fails or shows no serverless operator pods.

Fix

Install the OpenShift Serverless Operator using OperatorHub or the CLI YAML from this lab.

Verify:

oc get csv -n openshift-serverless
Code language: JavaScript (javascript)

Expected phase:

Succeeded

Problem 4: Knative Serving Is Missing

Symptom

oc get ksvc
Code language: JavaScript (javascript)

returns an error such as:

the server doesn't have a resource type "ksvc"

Cause

Knative Serving is not installed.

Fix

Create the KnativeServing resource:

oc apply -f knative-serving.yaml
Code language: CSS (css)

Verify:

oc get pods -n knative-serving
oc api-resources | grep ksvc
Code language: JavaScript (javascript)

Problem 5: Function Build Fails

Possible Causes

  1. Podman or Docker is not running.
  2. Image registry login failed.
  3. Registry route is not exposed.
  4. TLS verification failed.
  5. Laptop does not have enough CPU or memory.
  6. Network/VPN blocks registry access.

Check

podman version
podman info

Check registry route:

oc get route default-route -n openshift-image-registry
Code language: JavaScript (javascript)

Check registry login:

REGISTRY_HOST=$(oc get route default-route -n openshift-image-registry -o jsonpath='{.spec.host}')

podman login --tls-verify=false \
  -u "$(oc whoami)" \
  -p "$(oc whoami -t)" \
  "$REGISTRY_HOST"
Code language: PHP (php)

Try deploy again:

kn func deploy -i "$REGISTRY_HOST/lab14-serverless-functions/lab14-hello-func:latest"
Code language: JavaScript (javascript)

Problem 6: Function Deploy Fails with Registry Push Error

Cause

The function image cannot be pushed to the registry.

Fix Option 1: Re-login to OpenShift Registry

REGISTRY_HOST=$(oc get route default-route -n openshift-image-registry -o jsonpath='{.spec.host}')

podman login --tls-verify=false \
  -u "$(oc whoami)" \
  -p "$(oc whoami -t)" \
  "$REGISTRY_HOST"
Code language: PHP (php)

Deploy again:

kn func deploy -i "$REGISTRY_HOST/lab14-serverless-functions/lab14-hello-func:latest"
Code language: JavaScript (javascript)

Fix Option 2: Use Quay.io

podman login quay.io
kn func deploy -i "quay.io/<your-quay-username>/lab14-hello-func:latest"
Code language: HTML, XML (xml)

Problem 7: Function URL Does Not Open

Check

oc get ksvc lab14-hello-func
oc describe ksvc lab14-hello-func
Code language: JavaScript (javascript)

Check URL:

oc get ksvc lab14-hello-func -o jsonpath='{.status.url}'
Code language: PHP (php)

Check Knative route:

oc get routes.serving.knative.dev
Code language: CSS (css)

Check pods:

oc get pods
Code language: JavaScript (javascript)

Invoke again:

curl -v "$FUNC_URL"
Code language: JavaScript (javascript)

If DNS fails on your laptop, check CRC status:

crc status

Problem 8: Function Returns Slowly on First Request

This can be normal.

If the function scaled to zero, the first request must start a new pod.

This is called:

scale-from-zero
Code language: JavaScript (javascript)

Second and later requests are usually faster while the pod is still running.


Problem 9: No Function Pod Is Running

This may be normal if the function scaled to zero.

Invoke the function:

curl -s "$FUNC_URL"
Code language: JavaScript (javascript)

Then check pods immediately:

oc get pods -l serving.knative.dev/service=lab14-hello-func
Code language: JavaScript (javascript)

Problem 10: Web Console Function Creation Is Not Available

The web console function workflow requires additional setup, including OpenShift Pipelines and function pipeline tasks.

For this lab, use the CLI workflow with:

kn func create
kn func deploy
kn func invoke

This is simpler and more reliable for beginner students.


Part 28: Cleanup Student Resources

Delete the function:

oc delete ksvc lab14-hello-func
Code language: JavaScript (javascript)

Or, from the function directory:

kn func delete
Code language: JavaScript (javascript)

Delete the project:

oc delete project lab14-serverless-functions
Code language: JavaScript (javascript)

Verify:

oc get project lab14-serverless-functions
Code language: JavaScript (javascript)

Expected result:

NotFound

Part 29: Optional Admin Cleanup

Only run this if the OpenShift Local cluster is used only for this lab.

Do not remove shared Serverless components from a classroom cluster unless the instructor confirms.

Log in as kubeadmin:

oc login -u kubeadmin https://api.crc.testing:6443
Code language: JavaScript (javascript)

Delete Knative Serving:

oc delete knativeserving.operator.knative.dev knative-serving -n knative-serving
Code language: CSS (css)

Delete Knative Serving namespace:

oc delete namespace knative-serving
Code language: JavaScript (javascript)

Delete the Serverless Operator subscription:

oc delete subscription serverless-operator -n openshift-serverless
Code language: JavaScript (javascript)

List CSVs:

oc get csv -n openshift-serverless
Code language: JavaScript (javascript)

Delete the Serverless CSV shown in the output if required:

oc delete csv <serverless-csv-name> -n openshift-serverless
Code language: HTML, XML (xml)

Delete the Serverless namespace:

oc delete namespace openshift-serverless
Code language: JavaScript (javascript)

Part 30: Lab Summary

In this lab, you installed and used OpenShift Serverless Functions.

You created:

ResourcePurpose
OpenShift Serverless OperatorManages Knative components
KnativeServingInstalls Knative Serving
ProjectIsolated namespace for the function
Function sourceNode.js function code
Container imageBuilt function runtime image
Knative ServiceServerless runtime resource
RevisionImmutable version of the function
ConfigurationKnative configuration state
Knative RouteFunction URL routing
PodRuntime instance created when traffic arrives

You verified that:

  1. OpenShift Serverless is installed.
  2. Knative Serving is running.
  3. kn func can create functions.
  4. A Node.js function can be deployed.
  5. The function can be invoked by URL.
  6. The function can scale to zero.
  7. The function can scale from zero when traffic arrives.
  8. Updating the function creates a new revision.

Part 31: Review Questions

Question 1

What is OpenShift Serverless based on?

Answer

Knative.


Question 2

Which OpenShift Serverless component is required to run functions?

Answer

Knative Serving.


Question 3

Which CLI command creates a function?

Answer

kn func create

Question 4

Which CLI command deploys a function?

Answer

kn func deploy

Question 5

Which CLI command invokes a function?

Answer

kn func invoke

Question 6

What OpenShift resource is created when a function is deployed?

Answer

A Knative Service.


Question 7

What command lists Knative Services?

Answer

oc get ksvc
Code language: JavaScript (javascript)

Question 8

What is scale-to-zero?

Answer

Scale-to-zero means the function pod is removed when the function is idle.


Question 9

What is scale-from-zero?

Answer

Scale-from-zero means a new function pod is created automatically when a request arrives.


Question 10

Why does the first request sometimes take longer?

Answer

Because the function may need to start from zero pods before it can serve the request.


Part 32: Instructor Notes

This lab intentionally uses the CLI-based kn func workflow instead of the web-console function creation workflow.

Reason:

The web-console function workflow requires additional setup such as OpenShift Pipelines and function-specific pipeline tasks. That is useful for an advanced lab, but it adds too much complexity for a first serverless functions lab.

Recommended follow-up labs:

  1. Create functions from the OpenShift web console.
  2. Install OpenShift Pipelines for function builds.
  3. Connect an event source to a function.
  4. Use Knative Eventing.
  5. Trigger functions from Kafka.
  6. Configure function environment variables.
  7. Use ConfigMaps and Secrets with functions.
  8. Configure function concurrency.
  9. Configure autoscaling.
  10. Configure custom domains and TLS.
  11. Observe serverless metrics.
  12. Deploy Quarkus, Python, Go, and TypeScript functions.
  13. Deploy serverless applications using GitOps.

Part 33: Instructor Pre-Validation Checklist

Before delivering this lab to students, run:

crc status
oc whoami
oc get nodes
Code language: JavaScript (javascript)

Validate Serverless Operator:

oc get csv -n openshift-serverless
Code language: JavaScript (javascript)

Validate Knative Serving:

oc get pods -n knative-serving
oc get knativeserving.operator.knative.dev knative-serving -n knative-serving \
  --template='{{range .status.conditions}}{{printf "%s=%s\n" .type .status}}{{end}}'
Code language: PHP (php)

Validate CLI:

kn version
kn func --help
podman version

Validate registry route:

oc get route default-route -n openshift-image-registry
Code language: JavaScript (javascript)

Create a test function:

oc new-project lab14-validation
kn func create -l node -t http lab14-test-func
cd lab14-test-func

REGISTRY_HOST=$(oc get route default-route -n openshift-image-registry -o jsonpath='{.spec.host}')

kn func deploy -i "$REGISTRY_HOST/lab14-validation/lab14-test-func:latest"

FUNC_URL=$(oc get ksvc lab14-test-func -o jsonpath='{.status.url}')
curl -s "$FUNC_URL"
Code language: PHP (php)

Clean up:

cd ..
oc delete project lab14-validation
rm -rf lab14-test-func
Code language: JavaScript (javascript)

If the function deploys and responds successfully, the lab is ready for students.


Final Outcome

You have successfully completed OpenShift Lab 14.

You installed OpenShift Serverless, installed Knative Serving, created a Node.js serverless function, deployed it as a Knative Service, invoked it through a URL, checked the generated Knative resources, and observed serverless scale-to-zero behavior.

The final workflow is:

Function source code
  -> kn func build/deploy
  -> container image
  -> Knative Service
  -> Revision
  -> Pod on demand
  -> Function URL
  -> scale to zero when idle
Code language: JavaScript (javascript)

This is one of the most important OpenShift developer workflows for event-driven and request-driven workloads.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Best DevOps Tools in 2024

hereโ€™s a clear, structured breakdown of the Best DevOps Tools (grouped by categories), so you can use it for learning, training, or posts. ๐Ÿš€ Best DevOps Tools…

Read More

OpenShift Tutorial โ€“ Deploy and Access Your First Applications using OpenShift Local

How to install oc? OpenShift: How to Install OpenShift CLI oc How to login? Login to the Openshift using Web Console and CLI using oc Copy the admin…

Read More

OpenShift Lab 13: Deploy a Java Spring Boot Application with MySQL Using the OpenShift Web Console

Lab Objective In this lab, you will deploy a Java Spring Boot application on OpenShift using the OpenShift web console. You will deploy two components: The Java…

Read More

OpenShift Lab 12: Deploy an Application from an Existing Container Image Using the OpenShift Web Console

Lab Objective In this lab, you will deploy an application on OpenShift from an existing container image. This lab is different from building an application from source…

Read More

OpenShift: How to Install OpenShift CLIย oc

Option – 1 – REDHAT Websites URL – https://access.redhat.com/downloads/content/290/ver=4.18/rhel—9/4.18.11/x86_64/product-software Option – 2 – OKD Websites The OKD (Origin Community Distribution of Kubernetes for OpenShift) is the open-source…

Read More

OpenShift Lab 11: Build and Deploy an Application from Source Code Using the OpenShift Web Console

Lab Objective In this lab, you will build and deploy a web application from source code stored in a Git repository using the OpenShift web console. You…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Skylar Bennett
Skylar Bennett
18 days ago

The guide explains the deployment process for OpenShift Serverless Functions clearly, but it could also cover some production-oriented considerations. For workloads with unpredictable traffic patterns, tuning autoscaling behavior is important to balance resource efficiency against cold-start latency. Additionally, as serverless environments grow, having strong observability practicesโ€”such as centralized logging, distributed tracing, and function-level metricsโ€”becomes essential for diagnosing failures and understanding event flows across services.

1
0
Would love your thoughts, please comment.x
()
x