riff is for functions

riff is for functions

  • Docs
  • Blog
  • GitHub
  • Slack

›Getting Started

Version (v0.4.x)

  • v0.6.x (snapshot)
  • v0.5.x
  • v0.3.x

Getting Started

  • Pick your environment
  • GKE
  • Minikube
  • Docker for Mac
  • Docker for Windows

Runtimes

  • Core
  • Knative

Function Invokers

  • Java
  • Node.js
  • Command

CLI Reference

  • riff
  • riff doctor
  • riff completion
  • Credential

    • riff credential
    • riff credential apply
    • riff credential delete
    • riff credential list

    Build

    • riff function
    • riff function create
    • riff function delete
    • riff function list
    • riff function status
    • riff function tail
    • riff application
    • riff application create
    • riff application delete
    • riff application list
    • riff application status
    • riff application tail
    • riff container
    • riff container create
    • riff container delete
    • riff container list
    • riff container status

    Core Runtime

    • riff core
    • riff core deployer
    • riff core deployer create
    • riff core deployer delete
    • riff core deployer list
    • riff core deployer status
    • riff core deployer tail

    Knative Runtime

    • riff knative
    • riff knative adapter
    • riff knative adapter create
    • riff knative adapter delete
    • riff knative adapter list
    • riff knative adapter status
    • riff knative deployer
    • riff knative deployer create
    • riff knative deployer delete
    • riff knative deployer list
    • riff knative deployer status
    • riff knative deployer tail
Edit

Getting started on Docker for Mac

The following will help you get started running a riff function with Knative on Docker Community Edition for Mac.

Install Docker

Kubernetes and the kubectl CLI are now included with Docker Community Edition for Mac.

download Docker for mac

resize the VM

Once Docker is installed and running, use the Preferences feature in the Docker menu to open Advanced settings and configure your VM with 4GB of memory and 4 CPUs. Click on Apply & Restart. configure Docker VM

enable Kubernetes

Now enable Kubernetes, and wait for the cluster to start. enable Kubernetes

Confirm that your kubectl context is pointing to docker-desktop

kubectl config current-context

Install Helm

Helm is a popular package manager for Kubernetes. The riff runtime and its dependencies are provided as Helm charts.

Download and install the latest Helm 2.x client CLI for your platform. (Helm 3 is currently in alpha and has not been tested for compatibility with riff)

After installing the Helm CLI, initialize the Helm Tiller in our cluster.

kubectl create serviceaccount tiller -n kube-system
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount kube-system:tiller
helm init --wait --service-account tiller

NOTE: Please see the Helm documentation for additional Helm security configuration.

Install the riff CLI

The riff CLI is available to download from our GitHub releases page. Once installed, check that the riff CLI version is 0.4.0 or later.

riff --version
riff version 0.4.0 (d1b042f4247d8eb01ee0b9e984926028a2844fe8)

At this point it is useful to monitor your cluster using a utility like watch. To install on a Mac

brew install watch

Watch pods in a separate terminal.

watch -n 1 kubectl get pod --all-namespaces

Install riff using Helm

Load the projectriff charts

helm repo add projectriff https://projectriff.storage.googleapis.com/charts/releases
helm repo update

riff can be installed with or without Knative. The riff Core runtime is available in both environments, however, the riff Knative Runtime is only available if Knative is installed.

To install riff with Knative and Istio:

helm install projectriff/istio --name istio --version 0.4.x --namespace istio-system --set gateways.istio-ingressgateway.type=NodePort --wait
helm install projectriff/riff --name riff --version 0.4.x --set knative.enabled=true

Alternatively, install riff without Knative or Istio:

helm install projectriff/riff --name riff --version 0.4.x

Verify the riff install.

riff doctor
NAMESPACE     STATUS
riff-system   ok

RESOURCE                              READ      WRITE
configmaps                            allowed   allowed
secrets                               allowed   allowed
pods                                  allowed   n/a
pods/log                              allowed   n/a
applications.build.projectriff.io     allowed   allowed
containers.build.projectriff.io       allowed   allowed
functions.build.projectriff.io        allowed   allowed
deployers.core.projectriff.io         allowed   allowed
processors.streaming.projectriff.io   allowed   allowed
streams.streaming.projectriff.io      allowed   allowed
adapters.knative.projectriff.io       allowed   allowed
deployers.knative.projectriff.io      allowed   allowed

apply build credentials

Use the riff CLI to apply credentials for a container registry. If you plan on using a namespace other than default add the --namespace flag. Replace the ??? with your docker username.

DOCKER_ID=???
riff credential apply my-creds --docker-hub $DOCKER_ID --set-default-image-prefix

You will be prompted to provide the password.

Create a function

This step will pull the source code for a function from a GitHub repo, build a container image based on the node function invoker, and push the resulting image to your Docker Hub repo.

riff function create square \
  --git-repo https://github.com/projectriff-samples/node-square  \
  --artifact square.js \
  --tail

After the function is created, you can see the built image by listing functions.

riff function list
NAME     LATEST IMAGE                                                                                                ARTIFACT    HANDLER   INVOKER   STATUS   AGE
square   index.docker.io/$DOCKER_ID/square@sha256:ac089ca183368aa831597f94a2dbb462a157ccf7bbe0f3868294e15a24308f68   square.js   <empty>   <empty>   Ready    1m13s

Create a Knative deployer

The Knative Runtime is only available on clusters with Istio and Knative installed. Knative deployers run riff workloads using Knative resources which provide auto-scaling (including scale-to-zero) based on HTTP request traffic, and routing.

riff knative deployer create knative-square --function-ref square --tail

After the deployer is created, you can see the hostname by listing deployers.

riff knative deployer list
NAME             TYPE       REF      HOST                                 STATUS   AGE
knative-square   function   square   knative-square.default.example.com   Ready    28s

invoke the function

Knative configures HTTP routes on the istio-ingressgateway. Requests are routed by hostname.

Look up the nodePort for the ingressgateway; you should see a port value like 30195.

INGRESS_PORT=$(kubectl get svc istio-ingressgateway --namespace istio-system --output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
echo $INGRESS_PORT

Invoke the function by POSTing to the ingressgateway, passing the hostname and content-type as headers.

curl http://localhost:$INGRESS_PORT/ -w '\n' \
-H 'Host: knative-square.default.example.com' \
-H 'Content-Type: application/json' \
-d 7
49

Create a Core deployer

The Core runtime is available on all riff clusters. It deploys riff workloads as "vanilla" Kubernetes deployments and services.

riff core deployer create k8s-square --function-ref square --tail

After the deployer is created, you can see the service name by listing deployers.

riff core deployers list
NAME         TYPE       REF      SERVICE               STATUS   AGE
k8s-square   function   square   k8s-square-deployer   Ready    16s

invoke the function

In a separate terminal, start port-forwarding to the ClusterIP service created by the deployer.

kubectl port-forward service/k8s-square-deployer 8080:80
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080

Make a POST request to invoke the function using the port assigned above.

curl http://localhost:8080/ -w '\n' \
-H 'Content-Type: application/json' \
-d 8
64

NOTE: unlike Knative, the Core runtime will not scale deployments down to zero.

Cleanup

riff knative deployer delete knative-square
riff core deployer delete k8s-square
riff function delete square

Upgrading

If you need to upgrade riff, we recommend uninstalling and then reinstalling.

Uninstalling

You can use helm to uninstall riff.

# remove any riff resources
kubectl delete riff --all-namespaces --all

# remove any Knative resources (if Knative runtime is enabled)
kubectl delete knative --all-namespaces --all

# remove riff
helm delete --purge riff
kubectl delete customresourcedefinitions.apiextensions.k8s.io -l app.kubernetes.io/managed-by=Tiller,app.kubernetes.io/instance=riff

# remove istio (if installed)
helm delete --purge istio
kubectl delete namespace istio-system
kubectl get customresourcedefinitions.apiextensions.k8s.io -oname | grep istio.io | xargs -L1 kubectl delete

Alternatively you can reset the Kubernetes cluster (this will remove all state including riff).

reset Kubernetes using Preferences/Reset

← MinikubeDocker for Windows →
  • Install Docker
    • resize the VM
    • enable Kubernetes
  • Install Helm
  • Install the riff CLI
  • Install riff using Helm
    • apply build credentials
  • Create a function
  • Create a Knative deployer
    • invoke the function
  • Create a Core deployer
    • invoke the function
  • Cleanup
  • Upgrading
  • Uninstalling
riff is for functions
Docs
Versions
Community
BlogGitHubSlackKnativeTwitter
More
Privacy PolicyTerms of UseCode of Conduct
Deployed by Netlify
Copyright © 2021 VMware, Inc