From c09361e74fa5741440b0fc1219c1b097cc5b34b0 Mon Sep 17 00:00:00 2001 From: Theo Pack Date: Sat, 5 Oct 2019 17:15:38 +0200 Subject: [PATCH] Add nuclio example --- README.md | 1 + nuclio/README.md | 25 +++++++++++++++++++++++++ nuclio/app.py | 9 +++++++++ 3 files changed, 35 insertions(+) create mode 100644 nuclio/README.md create mode 100644 nuclio/app.py diff --git a/README.md b/README.md index 222dcaa..f23fdeb 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ This repo contains a simple app and steps for deploying it to several popular se * [OpenFaas](https://www.openfaas.com/) * [OpenWhisk](http://openwhisk.incubator.apache.org) * [Fn](http://fnproject.io) +* [Nuclio](https://github.com/nuclio/nuclio) ## Usage See the README's within each frameworks directory. diff --git a/nuclio/README.md b/nuclio/README.md new file mode 100644 index 0000000..525ba9d --- /dev/null +++ b/nuclio/README.md @@ -0,0 +1,25 @@ +# Template for deploying an app to nuclio +[Nuclio](https://github.com/nuclio/nuclio) + +## Pre-reqs +* Kube cluster with nuclio installed +* kubectl and [nuctl](https://github.com/nuclio/nuclio/releases) installed +* Prepared private docker registry with configured credentials secret. Nuclio need to push docker images into a repository. [see this](https://github.com/nuclio/nuclio/blob/master/docs/setup/k8s/getting-started-k8s.md#install-nuclio) + +## Deploy to Nuclio +> Note: If you are using Docker Hub, the URL here includes your username - `docker.io/`. +``` +nuctl deploy helloworld -n nuclio -p https://raw.githubusercontent.com/appvia/serverless-kube/master/nuclio/app.py --registry +``` + +## Call the function from the CLI +``` +$ nuctl invoke -n nuclio helloworld +``` + +## Call the function using http +``` +$ kubectl port-forward --namespace nuclio $(kubectl get pod --namespace nuclio --selector="nuclio.io/app=functionres,nuclio.io/class=function,nuclio.io/function-name=helloworld,nuclio.io/function-version=latest,nuclio.io/project-name=default" --output jsonpath='{.items[0].metadata.name}') 8080:8080 & + +$ curl localhost:8080 +``` \ No newline at end of file diff --git a/nuclio/app.py b/nuclio/app.py new file mode 100644 index 0000000..3430122 --- /dev/null +++ b/nuclio/app.py @@ -0,0 +1,9 @@ +def handler(context, event): + response_body = f'Got {event.method} to {event.path} with "{event.body}"' + + context.logger.debug('This is a debug level message') + + return context.Response(body=response_body, + headers=None, + content_type='text/plain', + status_code=200) \ No newline at end of file