Getting Started with OpenFaaS Part 1 : (Local Deployment)

·

3 min read

OpenFaaS is open-source community-driven function as a service solution as indicated by its tag line "OpenFaaS - Serverless Functions Made Simple"

OpenFaaS Deployement

OpenFaaS is built around the PLONK Stack providing management of the compute. Apart from Kubernetes (as in the 'K') it can also be deployed to a variety of container orchestrators (like OpenShift) or even run on a single host with faasd.

PLONK Stack

PLONK is a Cloud Native stack for building applications which stands for:

  • Prometheus - metrics and time-series
  • Linux
  • OpenFaaS - management and auto-scaling of compute - PaaS/FaaS, a developer-friendly abstraction on top of Kubernetes. Each function or microservice is built as an immutable Docker container or OCI-format image.
  • NATS - asynchronous message bus / queue
  • Kubernetes - declarative, extensible, scale-out, self-healing clustering

Getting Started

So lets get started !

We will be using openfaas with kubernetes (for orchestration) and docker (for container registry).

Pre-requisites

1. Install Docker

Install Docker Desktop CE Edition. If you already have docker installed you can proceed to Step 2.

Download and install the Docker Desktop from here

When using Windows

  • Use Windows 10 Pro or Enterprise editions only
  • Please ensure you use the Linux containers Docker daemon by using the Docker menu in the Windows task bar notification area.
  • Install and use Git Bash as the terminal client.

2. OpenFaaS CLI

You can install the OpenFaaS CLI using the official bash script. The CLI is used to scaffold new functions, build, deploy and invoke functions. You can find out commands available for the cli with faas-cli --help

With MacOS or Linux run the following in a Terminal:

$ curl -sLSf https://cli.openfaas.com | sudo sh

For Windows, run this in Git Bash:

$ curl -sLSf https://cli.openfaas.com | sh

Test the faas-cli. Open a Terminal or Git Bash window and type in:

$ faas-cli help
$ faas-cli version

3. Setup Kubernetes

Open the Docker Desktop Preferences/Settings and check enable Kubernetes Open a Terminal or Git Bash window and check kubectl (kubernetes cli) is available

$ kubectl --version

4. Deploy OpenFaaS

There are many different ways to deploy openfaas on the cluster. The most simplest way is by using arkade

Get arkade

For MacOS / Linux:

curl -SLsf https://dl.get-arkade.dev/ | sudo sh

For Windows:

curl -SLsf https://dl.get-arkade.dev/ | sh

Install OpenFaaS app

As we are using local Kubernetes cluster, run:

arkade install openfaas

Login to OpenFaaS

  • Check the gateway is ready
    kubectl rollout status -n openfaas deploy/gateway
    

OpenFaaS by default uses basic authentication for any connection. The OpenFaaS gateway URL will be http://localhost:31112

In case of any issues check if you are using the correct port. You can check for the NodePort entry. (You can use GUI for interacting with Kubernetes from here )

  • Log In to CLI Login to the faas-cli using the below steps
export OPENFAAS_URL="http://localhost:31112" # Populate as above

# This command retrieves your password
PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo)

# This command logs in and saves a file to ~/.openfaas/config.yml
echo -n $PASSWORD | faas-cli login --username admin --password-stdin

Testing things out

As all the components are installed, you can now test out the OpenFaaS using its GUI. Simply open the URL from above step in a browser. Enter the username as admin and password as the retrieved from the above step

We can deploy some sample functions and then use them to test things out:

$ faas-cli deploy -f https://raw.githubusercontent.com/openfaas/faas/master/stack.yml

Now goto the UI and play with the functions

Next up we will be looking at creating new custom functions using python. Till next time.

Did you find this article valuable?

Support PrSh9 by becoming a sponsor. Any amount is appreciated!