Three functions from the OpenFaaS store have been packaged as "knative serving" definitions. No change to the container or code is needed.
- Inception - identify the content of images with machine-learning - is it a bird, a plane or what?
- Colorise - turn any black and white image into colour
- NodeInfo - give system info, pass "verbose" as the body for network adapters etc.
-
Clone gist
-
Setup outbound traffic in Istio - https://github.com/knative/docs/blob/master/serving/outbound-network-access.md
-
Deploy with
kubectl apply -f
-
Try inception function:
Find knative IP and set in export KNATIVE_IP=
kubectl get svc knative-ingressgateway -n istio-system
Find name of OpenFaaS function:
kubectl get services.serving.knative.dev inception-openfaas -o=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain
echo -n "https://digital-photography-school.com/wp-content/uploads/2007/02/black-and-white-tips.jpg" | \
curl -X POST --data-binary @- -H "Host: inception-openfaas.default.example.com" $KNATIVE_IP -i
HTTP/1.1 200 OK
content-length: 544
content-type: application/x-www-form-urlencoded
date: Thu, 26 Jul 2018 22:10:22 GMT
x-duration-seconds: 2.702005
x-envoy-upstream-service-time: 3008
server: envoy
[{"score": 0.9821120500564575, "name": "coil"}, {"score": 0.005453020334243774, "name": "snail"}, {"score": 0.0016122378874570131, "name": "chambered nautilus"}, {"score": 0.000917674507945776, "name": "nematode"}, {"score": 0.0008158141863532364, "name": "bannister"}, {"score": 0.0005424919654615223, "name": "ram"}, {"score": 0.00037825442268513143, "name": "hognose snake"}, {"score": 0.00021164452482480556, "name": "combination lock"}, {"score": 0.00019924681691918522, "name": "buckle"}, {"score": 0.0001905750104924664, "name": "hog"}]
You may have to run this several times since Istio will "time-out" the request. If you can figure out how to set a longer timeout that'd be better. Post a comment to the Gist.
Colorise will need a longer timeout.
NodeInfo will work with the default timeout, if you trigger auto-scaling you'll see the different hostnames coming back.
See the [OpenFaaS function store](Function store manifest: https://github.com/openfaas/store ) for more examples.
You can also generate/build/push your OpenFaaS functions with the OpenFaaS CLI and create your own serving YAML files for deployment onto knative.
- Building a new OpenFaaS Golang function and deploying onto knative:
brew install faas-cli # or curl -sLS https://cli.openfaas.comn | sh
faas-cli new --lang go go-native --prefix=alexellis2
# Edit go-native/handler.go
faas-cli build -f go-native.yml
faas-cli push -f go-native.yml (pushing docker.io/alexellis2/go-native:latest)
# Create serving.yaml definition or copy example below and set image to "docker.io/alexellis2/go-native:latest"
# Deploy with kubectl apply -f serving.yaml
Deploy OpenFaaS with helm, open the UI and browse the store, then click "Deploy".
Then learn how to master Serverless Functions with OpenFaaS through the self-paced online workshop.