OpenFaaS on Minikube: Serverless on Kubernetes for Windows 10

This blog post will guide you through installing and getting started with OpenFaaS and Kubernetes through the use of Minikube on Windows 10.

Copyright © OpenFaaS Ltd

If you are also using minikube on Mac, then please checkout this guide from the author of OpenFaaS, Alex Ellis, on installing OpenFaaS on minikube for Mac.

https://medium.com/devopslinks/getting-started-with-openfaas-on-minikube-634502c7acdf

Contents

  1. Minikube, Docker and Other Dependencies
  2. Install the OpenFaaS CLI program: faas-cli
  3. Install OpenFaaS
  4. Deploy Your First Function from the OpenFaaS Function Store
  5. Build and Deploy a CSharp function using the OpenFaaS CLI

Minikube, Docker and Other Dependencies

  1. Chocolatey package manager for Windows: Please use this guide from my blog post here if you need help getting started (https://medium.com/@JockDaRock/installing-the-chocolatey-package-manager-for-windows-3b1bdd0dbb49).
  2. Minikube: You will need to have minikube installed on Windows before starting with OpenFaaS. Please also use the following guide I compiled for using Minikube on HyperV for Windows 10 (https://medium.com/@JockDaRock/minikube-on-windows-10-with-hyper-v-6ef0f4dc158c).
  3. Docker: You can use the Chocolatey package to install this one, choco install docker. You will need this in combination with the OpenFaaS cli program to build the Docker images that hold the functions.
  4. Helm: Once you have the Chocolatey Package manager and Minikube installed on your Windows 10 computer, we will need to install Helm which is a package manager for Kubernetes. We will use Helm to install OpenFaaS to our Kubernetes Cluster on Minikube. Use this guide to install Helm (https://medium.com/@JockDaRock/take-the-helm-with-kubernetes-on-windows-c2cd4373104b)
  5. Git: Install git on Windows. We will use git to copy the code repos we need for OpenFaaS. In an Admin Windows command line, type choco install git.

6. Signup for a Docker Hub account (if you do not already have a Docker Hub account). We will need a place to push the Docker image of our function, for the Build and Deploy a CSharp function using the OpenFaaS CLI portion of this guide. You can sign up here (https://hub.docker.com/). It is free and easy to signup.

Once you have completed those steps, you are ready to install OpenFaaS.

Optional, but Recommended Packages: In the last section of this tutorial I will be using a few programs that are not installed with Windows. You can use native Windows packages to accomplish those tasks if you are more familiar with those programs. That being said all of the packages I will be using can also be installed using chocolatey and the following commands: choco install curl, choco install notepadplusplus, choco install postman.

Install the OpenFaaS CLI program: faas-cli

Open an Admin command line window and use chocolatey to install the OpenFaaS CLI program.

choco install faas-cli

Install OpenFaaS

To install OpenFaas we need to clone the git repo for faas-netes, which is the Kubernetes implementation of OpenFaaS. Navigate to a directory of your choice on the Windows command line and then clone the repo.

git clone https://github.com/openfaas/faas-netes

Change the directory to where faas-netes was downloaded.

cd faas-netes

Assuming you installed Helm from the packages section, use the following Helm command to install OpenFaaS to your Kubernetes Cluster on Minikube.

Note: If you have not initialized Helm for your Minikube cluster when you installed it to Windows, you can do so now by typing helm init in the command line window.
helm upgrade --install --debug --reset-values --set async=false --set rbac=false openfaas openfaas

Let’s check to make sure OpenFaaS is running by looking to see if the Web UI is up.

First we need to find the IP address. Type minikube ip in your command line window.

minikube ip

Using that IP address navigate to your IP address of your minikube on port 31112.

http://<minikube_ip>:31112/ui/

You now have OpenFaaS installed! Time for the fun.

Deploy Your First Function from the OpenFaaS Function Store

We are going to deploy our first function with OpenFaaS using the Web UI and the Function Store.

In a web browser navigate to the same URL we used to get to the Web UI.

http://<minikube_ip>:31112/ui/

Click on the Deploy New Function button.

Select the nslookup function and then click Deploy.

In the Request Body type in a domain name, to test the nslookup function, e.g developer.cisco.com, and then click the Invoke button.

If you prefer to call the function in a more programmatic way and you have one of the Optional, but Recommended packages installed for this tutorial. From the command line you can use the curl command to call the function.

curl -X POST http://<minikube_ip>:31112/function/nslookup -d 'developer.cisco.com'

Or Postman…

Congrats on deploying your first function!

Build and Deploy a CSharp function using the OpenFaaS CLI program

Using the Windows command line. In a directory of your choosing create an additional directory named functions and then change to that directory on the command line.

mkdir functions && cd functions

Using the OpenFaaS CLI program pull down the code templates we will use to build and deploy our function.

faas-cli template pull

Create a new function with faas-cli and the C# language.

faas-cli new win-func --lang csharp

This will have created a file folder called win-func and a win-func.yml file.

In the win-func folder their is a file called FunctionHandler.cs. I will be editing this file with the NotePad++ program. However you can use the native Windows Notepad editor if you want to edit the csharp file that way.

Open the FunctionHandler.cs handler in your text / code editor.

On line 9, at the end of Console.WriteLine, add the following text…

+ ". Welcome to TEAM SERVERLESS"

Save the file.

Using the same editor to open the win-func.yml file.

Edit the gateway to reflect the OpenFaaS gateway.

gateway: http://172.16.0.127:31112

Then edit the image portion to reflect your Docker Hub username and the name of your function.

image: <docker_hub_username>/win-func

Save the win-func.yml file.

In a command line window, build the function with the faas-cli.

faas-cli build -f win-func.yml

If you have not already done so, login to your docker hub account from the CLI.

docker login

Now push the function image to docker hub.

faas-cli push -f win-func.yml

Deploy the function to the Kubernetes cluster.

faas-cli deploy -f win-func.yml

Now we will test the function. On the OpenFaas Web UI, write a message in the Request Body and then Invoke the function.

Or you can use the curl function we used previously to invoke the win-func function from the Windows command line.

curl -X POST http://<minikube_ip>:31112/function/win-func -d "OpenFaaS Rocks!"

You are now a Serverless ninja!

Last Words

Visit the GitHub repo (https://github.com/openfaas/faas), star the project, and join the community.

You can also suggest and submit functions to the function store (https://github.com/openfaas/store). Check out this blog to learn about my first submission to the function store.

Checkout this guide for using Kubernetes in an environment that is closer to what you might see in production.

If you are interested in learning more about what serverless is from an architectural standpoint and how OpenFaaS fits in that picture, then please watch this YouTube video from Alex Ellis from KubeCon on OpenFaaS.

Follow OpenFaaS on Twitter for all the latest Cool Hacks, demos and news, Or follow me on Twitter, JockDaRock, for cool tech like this on a regular basis.

Also check out more of my blogs on medium by visiting https://medium.com/@JockDaRock. Cheers!