TechXchange 2024 Lab 1482 - Knative setup
These instructions should only be completed if:
-
You are the workshop instructor and you need to set up Knative on OCP so that all students will able to run InstantOn applications on that shared platform.
-
You are attempting to complete the lab on your own outside of a workshop environment.
It can also serve as a good reference for workshop attendees wishing to get details on what is involved in the Knative setup process.
- Initial lab setup
- Enhance the OpenShift Cloud Platform (OCP) environment
- Configure the Knative service
From the terminal, login as root:
su --login rootUse the password provided in the TechZone VM reservation.
cd /home/techzone
git clone https://github.com/rhagarty/techxchange-knative-setup.git
cd techxchange-knative-setupClick on the TechZone OCP reservation to find the link to the OpenShift console UI, along with the username and password to access the console.
From the OpenShift console UI, click the username in the top right corner, and select Copy login command.
Press Display Token and copy the Log in with this token command.
Paste the command into your terminal window. You should receive a confirmation message that you are logged in.
Perform the following steps to enhance OCP to better manage OCP services, such as Knative, which provides serverless or scale-to-zero functionality.
The Liberty Operator provides resources and configurations that make it easier to run Open Liberty applications on OCP.
kubectl apply --server-side -f https://raw.githubusercontent.com/OpenLiberty/open-liberty-operator/main/deploy/releases/1.2.1/kubectl/openliberty-app-crd.yamlSwitch to the "default" namespace:
oc project defaultType the following commands to install the serverless operator and Knative service.
oc apply -f serverless-subscription.yamloc apply -f serving.yamloc get csvYou should see the following output:
The Cert Manager adds certifications and certification issuers as resource types to Kubernetes
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.12.3/cert-manager.yamlKnative provides the serverless, or scale-to-zero feature of Kubernetes.
NOTE: The service may take a minute to load. after issuing the preceding
applycommand.
oc get knativeserving.operator.knative.dev/knative-serving -n knative-serving --template='{{range .status.conditions}}{{printf "%s=%s\n" .type .status}}{{end}}'Your output should match the following:
kubectl -n knative-serving edit cm config-features -oyamlAdd in the following line just bellow the “data” tag at the top:
kubernetes.containerspec-addcapabilities: enabledIMPORTANT: to save your change and exit the file, hit the escape key, then type
:x.
Knative will stop the pod if it does not receive a request in the specified time frame, which is set in a configuration yaml file. For this lab, the settings are in the serving.yaml file, and currently set to 30 seconds (as shown below).
apiVersion: operator.knative.dev/v1beta1
kind: KnativeServing
metadata:
name: knative-serving
namespace: knative-serving
spec:
config:
autoscaler:
scale-to-zero-grace-period: "30s"
scale-to-zero-pod-retention-period: "0s"



