The following are a recording of the steps performed for verifying the feasibility of Serverless Framework in a Knative-based OpenShift environment.
Serverless Framework 3.21.0 | OpenShift Container Platform 4.10 | Knative Operator 1.6.1 |
Original install instructions can be found here.
Note that for this POC, Knative-Eventing is not required.
oc apply -f https://github.com/knative/operator/releases/download/knative-v1.6.1/operator.yaml
$ oc get deployment knative-operator
NAME READY UP-TO-DATE AVAILABLE AGE
knative-operator 1/1 1 1 74s
cat <<EOF | oc apply -f -
---
apiVersion: v1
kind: Namespace
metadata:
name: knative-serving
---
apiVersion: operator.knative.dev/v1beta1
kind: KnativeServing
metadata:
name: knative-serving
namespace: knative-serving
spec:
ingress:
kourier:
enabled: true
config:
network:
ingress-class: "kourier.ingress.networking.knative.dev"
EOF
$ oc get deployment -n knative-serving
NAME READY UP-TO-DATE AVAILABLE AGE
3scale-kourier-gateway 1/1 1 1 7m40s
activator 1/1 1 1 7m45s
autoscaler 1/1 1 1 7m44s
autoscaler-hpa 1/1 1 1 7m42s
controller 1/1 1 1 7m44s
domain-mapping 1/1 1 1 7m43s
domainmapping-webhook 1/1 1 1 7m43s
net-kourier-controller 1/1 1 1 7m40s
webhook 1/1 1 1 7m42s
$ oc get KnativeServing knative-serving -n knative-serving
NAME VERSION READY REASON
knative-serving 1.6.0 True
If you don't already have a project in place, create a sample one from knative's template. It's a simply containerized Python web application returning "Hello World".
serverless create --template knative-docker --path myksvc
Step into the new project folder and continue to the next steps:
cd myksvc
Make sure you have the
DOCKER_HUB_USERNAME
andDOCKER_HUB_PASSWORD
environment variables set with your DockerHub credentials.
Update serverless-knative
development dependency in your project to use the patched fork and branch:
npm i --save-dev serverless-knative@github:dmartinol/serverless-knative#master
Deploy the serverless function and note the returning URL:
$ serverless deploy
Building Docker image "tomerfi/myksvc-hello:1660907694762"...
Pushing "tomerfi/myksvc-hello:1660907694762" to Container Registry...
Deploying Kubernetes namespace "sls-myksvc-dev"...
Deploying Knative service for function "myksvc-hello"...
Service Information
service: myksvc
namespace: sls-myksvc-dev
Deployed functions
hello:
- url: http://myksvc-hello.sls-myksvc-dev.example.com
If you lost the URL, get it back with
oc get rt -n sls-myksvc-dev myksvc-hello -o jsonpath={.status.url}
.
$ oc get svc kourier -n knative-serving -o jsonpath={.status.loadBalancer.ingress..hostname}
your-external-address.fake.co.m
Use kourier's URL as the target and the knative service URL (minus the http part) as the value for the Host header:
$ curl -HHost:myksvc-hello.sls-myksvc-dev.example.com your-external-address.fake.co.m
Hello World