Deploying on the Knative Runtime

This topic provides an overview of how to deploy function, application, and container workloads on the Knative runtime.

The Knative runtime is based on the Knative project which extends Kubernetes to run HTTP-triggered, zero-to-N auto-scaled workloads. Knative also includes ingress support for routing traffic to workloads on the cluster.

Requirements

  • PFS has been installed. In this release, the Knative runtime is included with PFS.
  • A function, application, or container has been built using the pfs CLI.

Create a deployer

Assuming a function named square, create a Knative deployer referencing the square function.

pfs knative deployer create square --function-ref square --tail
Created deployer "square"
default/square-726cg-deployment-5f66bbf458-tzpmg[user-container]: /usr/local/bin/jq
default/square-726cg-deployment-5f66bbf458-tzpmg[user-container]: Node started in 151ms
default/square-726cg-deployment-5f66bbf458-tzpmg[user-container]: Server starting with request-reply interaction model and payload argument type
default/square-726cg-deployment-5f66bbf458-tzpmg[user-container]: HTTP loaded in 89ms
default/square-726cg-deployment-5f66bbf458-tzpmg[user-container]: HTTP running on localhost:8080
default/square-726cg-deployment-5f66bbf458-tzpmg[user-container]: Function invoker started in 248ms

Deployers can also be created referencing applications and containers; new images are automatically detected and rolled out. Alternatively, a deployer created from an image needs to be manually updated to consume a new image.

After the deployer is created, get the host name by listing deployers.

pfs knative deployer list
NAME     TYPE       REF      HOST                         STATUS   AGE
square   function   square   square.default.example.com   Ready    11s

Configure HOST and INGRESS

Set the HOST value to match the workload being targeted, from pfs knative deployer list above.

HOST=square.default.example.com

Pick an INGRESS definition appropriate for the cluster.

# for clusters with a custom domain
INGRESS=$HOST

# for clusters with LoadBalancer services (like GKE)
INGRESS=$(kubectl get svc -n istio-system istio-ingressgateway -ojsonpath='{.status.loadBalancer.ingress[0].ip}')

# for clusters with NodePort services (like Minikube and Docker Desktop)
INGRESS=$(kubectl get nodes -ojsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}'):$(kubectl get svc -n istio-system istio-ingressgateway -ojsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')

The value of INGRESS will be constant for the life of the cluster.

Make the request using curl

curl $INGRESS -v -w '\n' -H "Host: $HOST" \
  -H 'Content-Type: application/json' \
  -d 7
* Rebuilt URL to: 35.184.153.67/
*   Trying 35.184.153.67...
* TCP_NODELAY set
* Connected to 35.184.153.67 (35.184.153.67) port 80 (#0)
> POST / HTTP/1.1
> Host: square.default.example.com
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 1
> 
* upload completely sent off: 1 out of 1 bytes
< HTTP/1.1 200 OK
< content-length: 2
< content-type: text/plain; charset=utf-8
< date: Mon, 19 Aug 2019 19:03:26 GMT
< x-powered-by: Express
< x-envoy-upstream-service-time: 7968
< server: istio-envoy
< 
* Connection #0 to host 35.184.153.67 left intact
49

Cleanup

Delete the deployer when done with the function. While Knative will automatically scale the workload to zero after a period of inactivity, it’s still a good idea to cleanup resources when no longer needed.

pfs knative deployer delete square
Deleted deployer "square"

Adapters

Adapters bridge a pfs build into an existing Knative Service or Configuration. This is handy when it is desirable to manage additional configuration that is not exposed by the Deployer resource, like routing to a specific revision.

The adapter updates the target resource with the most recent image as new images become available. Knative Serving creates new Revisions for each new image and routes traffic to that revision based the existing routing rules. The adapter will not modify the routing rules preserving any pinned revisions.