Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

Latest commit

 

History

History
367 lines (252 loc) · 11.6 KB

minikube.md

File metadata and controls

367 lines (252 loc) · 11.6 KB
id title sidebar_label
minikube
Getting started on Minikube
Minikube

The following will help you get started running a riff function with Knative on Minikube.

To get started with streaming or with the core runtime, follow these steps first, and then continue with the Streaming or Core runtime docs. Runtimes can be used separately or together.

Install Minikube

v0.6 of riff requires Kubernetes v1.15 or later.

Minikube is a Kubernetes environment which runs in a single virtual machine. See the Getting Started page for installation information.

Minikube uses a hypervisor driver that varies by operating system. Some drivers are provided with Minikube while others requires an extra installation step. See the Driver page for details.

For macOS we recommend using Hyperkit as the vm-driver and for Linux we suggest using the KVM (kvm2) driver. You can select what driver to use as default using the minikube config set vm-driver command. Newer versions of Minikube seem to default to usig the hyperkit driver for MacOS and it is provided with Minikube, so no extra install needed. The kvm2 driver for Linux does require an extra install step.

Install Docker

Installing Docker Community Edition is the easiest way get started with Docker. Since Minikube includes its own Docker daemon, you actually only need the docker CLI to run docker login for --local-path function builds. This means that if you want to, you can shut down the Docker Desktop app and depend on the Minikube Docker daemon by running eval $(minikube docker-env).

Install kubectl

kubectl is the Kubernetes CLI. It is used to manage minikube as well as hosted Kubernetes clusters.

Create a Minikube cluster

minikube config set memory 5192
minikube config set cpus 4

minikube start

Confirm that your kubectl context is pointing to the new cluster:

kubectl config current-context

monitor your cluster

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 kapp

kapp is a simple deployment tool for Kubernetes. The riff runtime and its dependencies are provided as standard Kubernetes yaml files, that can be installed with kapp.

You can install kapp using Homebrew on MacOS:

brew tap k14s/tap
brew install kapp

Alternatively, Download a recent binary for your platform from github. Move it into a directory on your path, and make it executable. Complete kapp installation instructions can be found here

Validate the installation.

kapp version
Client Version: 0.18.0

Succeeded

Install ytt

ytt is a tool for templating yaml. It can be used to apply changes to the distributed Kubernetes yamls files used to install riff.

You can install ytt using Homebrew on MacOS:

brew tap k14s/tap
brew install ytt

Alternatively, Download a recent binary for your platform from github. Move it into a directory on your path, and make it executable. Complete ytt installation instructions can be found here

Validate the installation.

ytt version
Version: 0.23.0

Install a snapshot build of the riff CLI

Recent snapshot builds of the riff CLI for macOS, Windows, or Linux, can be downloaded from GCS.

Alternatively, clone the riff CLI repo, and run make build install. This will require a recent go build environment. On macOS you can use brew install go.

Check that the riff CLI version is 0.6.0-snapshot.

riff --version
riff version 0.6.0-snapshot (443fc9125dd6d8eecd1f7e1a13fa93b88fd4f972)

Install riff Using kapp

riff can be installed with optional runtimes. The riff build system is always installed, and is required by each runtime.

NOTE: If you have riff v0.4.0 installed then you must first uninstall that version. See instructions in the v0.4.0 documentation.

Create a namespace for kapp to store configuration:

kubectl create ns apps

install riff Build

To install riff build and it's dependencies:

kapp deploy -n apps -a cert-manager -f https://storage.googleapis.com/projectriff/release/0.6.0-snapshot/cert-manager.yaml
kapp deploy -n apps -a kpack -f https://storage.googleapis.com/projectriff/release/0.6.0-snapshot/kpack.yaml
kapp deploy -n apps -a riff-builders -f https://storage.googleapis.com/projectriff/release/0.6.0-snapshot/riff-builders.yaml
kapp deploy -n apps -a riff-build -f https://storage.googleapis.com/projectriff/release/0.6.0-snapshot/riff-build.yaml

install Contour ingress controller

The Contour ingress controller can be used by both Knative and Core runtimes.

# ytt is used to convert the ingress service to NodePort because Minikube does not support `LoadBalancer` services.
ytt -f https://storage.googleapis.com/projectriff/release/0.6.0-snapshot/contour.yaml -f https://storage.googleapis.com/projectriff/charts/overlays/service-nodeport.yaml --file-mark contour.yaml:type=yaml-plain | kapp deploy -n apps -a contour -f - -y

install riff Knative Runtime

To optionally install riff Knative Runtime and it's dependencies:

kapp deploy -n apps -a knative -f https://storage.googleapis.com/projectriff/release/0.6.0-snapshot/knative.yaml
kapp deploy -n apps -a riff-knative-runtime -f https://storage.googleapis.com/projectriff/release/0.6.0-snapshot/riff-knative-runtime.yaml

verify riff installation

Resources may be missing if the corresponding runtime was not installed.

riff doctor
NAMESPACE     STATUS
default       ok
riff-system   ok

RESOURCE                                     NAMESPACE     NAME       READ      WRITE
configmaps                                   riff-system   builders   allowed   n/a
configmaps                                   default       *          allowed   allowed
secrets                                      default       *          allowed   allowed
pods                                         default       *          allowed   n/a
pods/log                                     default       *          allowed   n/a
applications.build.projectriff.io            default       *          allowed   allowed
containers.build.projectriff.io              default       *          allowed   allowed
functions.build.projectriff.io               default       *          allowed   allowed
deployers.core.projectriff.io                default       *          missing   missing
processors.streaming.projectriff.io          default       *          missing   missing
streams.streaming.projectriff.io             default       *          missing   missing
inmemoryproviders.streaming.projectriff.io   default       *          missing   missing
kafkaproviders.streaming.projectriff.io      default       *          missing   missing
pulsarproviders.streaming.projectriff.io     default       *          missing   missing
adapters.knative.projectriff.io              default       *          allowed   allowed
deployers.knative.projectriff.io             default       *          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/jldec/square@sha256:527053273ec98697dbdd88951f77edf82a9a46767125cd1e4348422fe5b8e09f   square.js   <empty>   <empty>   Ready    4m3s

Create a Knative deployer

The Knative Runtime is only available on clusters with 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 --ingress-policy External --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    19s

invoke the function

Knative configures HTTP routes on the ingress controller. Requests are routed by hostname.

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

MINIKUBE_IP=$(minikube ip)
INGRESS_PORT=$(kubectl get svc envoy  --namespace contour-external --output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
echo $MINIKUBE_IP:$INGRESS_PORT

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

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

Delete the function and deployer

riff knative deployer delete knative-square
riff function delete square

Uninstalling riff

You can delete your Minikube cluster and then recreate it (this will remove all state including riff).

minikube delete
minikube start --memory=4096 --cpus=4

Alternatively, you can use the following commands to uninstall riff:

remove any riff resources

kubectl delete riff --all-namespaces --all

remove riff Streaming Runtime

kapp delete -n apps -a riff-streaming-runtime
kapp delete -n apps -a keda

remove riff Core Runtime (if installed)

kapp delete -n apps -a riff-core-runtime

remove riff Knative Runtime (if installed)

kubectl delete knative --all-namespaces --all
kapp delete -n apps -a riff-knative-runtime
kapp delete -n apps -a knative

remove Contour

kapp delete -n apps -a contour

remove riff Build

kapp delete -n apps -a riff-build
kapp delete -n apps -a riff-builders
kapp delete -n apps -a kpack
kapp delete -n apps -a cert-manager