Skip to content

Latest commit

 

History

History
149 lines (112 loc) · 7.74 KB

getting-started-minikube.md

File metadata and controls

149 lines (112 loc) · 7.74 KB

Getting Started with Nuclio on Minikube

Follow this step-by-step guide to set up Nuclio on Minikube, which is a tool that lets you run Kubernetes locally.

In this document

Prerequisites

Before starting the set-up procedure, ensure that the following prerequisites are met:

Prepare Minikube

Start Minikube as you normally would. Note that the following command also enables role-based access control (RBAC) so that you can get more comfortable working with an RBAC-enabled Kubernetes cluster:

minikube start --kubernetes-version v1.17.9 --driver docker --extra-config=apiserver.authorization-mode=RBAC --addons ingress

Note: You may want to

  • Change the Kubernetes version. Currently, the recommended version is 1.17.9.
  • Add --addons ingress to your minikube start command to support creating function ingresses. Ensure that your function ingress appears on your hosts file (/etc/hosts). You can do this by running this command:
    echo "$(minikube ip) my-function.info" | sudo tee -a /etc/hosts

Bring up a Docker registry inside Minikube. You'll later push your functions to this registry:

Note: You can skip this step if you're a more advanced user and would like to use another type of registry, such as Docker Hub, Azure Container Registry (ACR), or Google Container Registry (GCR). See Getting started with Kubernetes for instructions.

minikube ssh -- docker run -d -p 5000:5000 registry:2

Before container images can be pushed to your built-in registry, you need to add its address ($(minikube ip):5000) to the list of insecure registries:

  • Docker for Mac OS - you can add it under Preferences | Daemon.
  • Linux - follow the instructions in the Docker documentation.

Install Nuclio

At this stage you should have a functioning Kubernetes cluster, a Docker registry, and a working Kubernetes CLI (kubectl), and you can proceed to install the Nuclio services on the cluster (i.e., deploy Nuclio).

Create a Nuclio namespace by running the following command:

Note: All Nuclio resources go into the "nuclio" namespace, and role-based access control (RBAC) is configured accordingly.

minikube kubectl -- create namespace nuclio

Add nuclio to helm repo charts: the following commands add Nuclio repo charts to your helm repos:

helm repo add nuclio https://nuclio.github.io/nuclio/charts

Deploy Nuclio to the cluster: the following command deploys Nuclio and its minimum required Kubernetes resources (including RBAC roles):

helm --namespace nuclio install nuclio nuclio/nuclio

Use the command minikube kubectl -- get pods --namespace nuclio to verify both the controller and dashboard are running.

Forward the Nuclio dashboard port: the Nuclio dashboard publishes a service at port 8070. To use the dashboard, you first need to forward this port to your local IP address:

minikube kubectl -- port-forward -n nuclio $(kubectl get pods -n nuclio -l nuclio.io/app=dashboard -o jsonpath='{.items[0].metadata.name}') 8070:8070

Deploy a function with the Nuclio dashboard

Browse to http://localhost:8070 (after having forwarded this port as part of the Nuclio installation) to see the Nuclio dashboard. Select the "default" project and then select New Function from the action toolbar to display the Create function page (http://localhost:8070/projects/default/create-function). Choose one of the predefined template functions, and select Deploy. The first build populates the local Docker cache with base images and other files, so it might take a while to complete, depending on your network. When the function deployment completes, you can select Test to invoke the function with a body.

Deploy a function with the Nuclio CLI (nuctl)

Run the following Nuclio CLI (nuctl) command from a command-line shell to deploy the example helloworld Go function. You can add the --verbose flag if you want to peek under the hood.

nuctl deploy helloworld -n nuclio -p https://raw.githubusercontent.com/nuclio/nuclio/master/hack/examples/golang/helloworld/helloworld.go --registry $(minikube ip):5000 --run-registry localhost:5000

Note: The difference between the two registries specified in this command and the reason for their addresses being different is as follows:

  • The --registry option defines the Docker registry onto which the function images that you build will be pushed. This is the registry that you previously brought up on your Minikube VM.
  • The --registry-run option defines the registry from which the kubelet Kubernetes "node agent" will pull the function images. Because this operation occurs in the Minikube VM, the command specifies localhost instead of the VM's IP address.

When the function deployment completes, you can get the function information by running the following CLI command:

nuctl get function helloworld

Sample output -

  NAMESPACE | NAME        | PROJECT | STATE | NODE PORT | REPLICAS  
  nuclio    | helloworld  | default | ready |     42089 | 1/1   

You can see from the sample output that the deployed function helloworld is running and using port 42089.

Run the following CLI command to invoke the function:

nuctl invoke helloworld --method POST --body '{"hello":"world"}' --content-type "application/json"

Sample output -

> Response headers:
Server = nuclio
Date = Thu, 18 Jun 2020 06:56:27 GMT
Content-Type = application/text
Content-Length = 21

> Response body:
Hello, from Nuclio :]

What's next?

See the following resources to make the best of your new Nuclio environment: