Getting Started with Nuclio on Minikube

On This Page

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

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.
  • Change the Minikube driver according to your environment and needs.
  • 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
The tutorial demonstrates how to bring up a local, simple, insecure Docker Registry. You can select, instead, to skip this step, and use any other Docker Registry, such as Docker Hub, Azure Container Registry (ACR), or Google Container Registry (GCR). For instructions, see Getting Started with Nuclio on Kubernetes.

Establish an SSH connection to the Minikube machine, and run the registry using docker:

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

Before Docker container images can be pushed to your newly created, insecure registry, you need to add its address ($(minikube ip):5000) to the list of insecure registries to instruct Docker to accept working against it:

  • 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 \
    --namespace nuclio \
    --http-trigger-service-type nodePort \
    --path https://raw.githubusercontent.com/nuclio/nuclio/master/hack/examples/golang/helloworld/helloworld.go \
    --registry $(minikube ip):5000 \
    --run-registry localhost:5000
Note
  • The command in the previous code snippet exposes the function externally using a nodePort. This is done for demonstration purposes only. For more information about exposing your function, see Exposing a function.
  • 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.

Because the function is exposed using a nodePort, you can run the following CLI command to invoke it:

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: