OpenFaaS in your local environment.
- Virtualbox - A a free and open-source hosted hypervisor for x86 virtualization.
- Vagrant - A tool for building and distributing development environments.
- faas-cli - Official CLI for OpenFaaS.
The Vagrantfile will create a virtual machine running Ubuntu 18.04 LTS (Bionic Beaver) in Virtualbox. It will install OpenFaaS using the faasd provider for a single node.
Run the following command to deploy openfaas:
$ vagrant up
You will be prompted with a message asking to select a Docker container registry (optional):
Choose a Container Registry Server:
1) Docker (docker.io)
2) GitHub (ghcr.io)
3) Quay (quay.io)
4) Other registry # <- provide your own url
5) Skip # <- skip if you want to keep your docker images locally
0) Quit # <- exit the script, you will have to destroy the VM afterwards
Enter selection [0-5]:
If you haven't selected Skip
or Quit
, you will be asked for your credentials:
Virtual machine needs your credentials for the container registry ghcr.io
Username: dysonfrost
Password:
When the VM is ready, vagrant will display some information:
### Vagrant Box provisioned! ###
------------------------------------------------------
Local OpenFaas is ready
URLS:
* OpenFaaS - http://192.168.50.2:8080
OpenFaaS credentials:
* username: admin
* password: <generated_password>
Login with faas-cli:
$ export OPENFAAS_URL=http://192.168.50.2:8080 # From Host
$ faas-cli login -u admin --password <generated_password>
------------------------------------------------------
If somehow you need to retrieve your generated password:
$ vagrant ssh
vagrant@openfaas:~$ sudo cat /var/lib/faasd/secrets/basic-auth-password
OpenFaas can be accessed from both the host and the guest VM, once logged in (see information above) you can build a new function.
$ faas-cli template store ls
# faas-cli template store pull <template>
$ faas-cli template store pull dockerfile
$ faas-cli template pull <repository_url>
# faas-cli new <function> --lang=<template>
$ faas-cli new hello-world --lang=dockerfile
version: 1.0
provider:
name: openfaas
gateway: http://192.168.50.2:8080
functions:
hello-world:
lang: dockerfile
handler: ./hello-world
image: hello-world:latest
gateway
- URL of the gateway (set to localhost if running from VM guest)lang
- Template associated with the functionhandler
- The folder / path to your handler / Dockerfile and any other source code you needimage
- The Docker image name. If you are going to push to a container registry change the prefix of your image - i.e. ghcr.io/dysonfrost/hello-world:latest
# faas-cli build -f <function>.yml
$ faas-cli build -f hello-world.yml
Skip the following steps if you do not intend to use a remote registery to invoke a function.
# faas-cli push -f <function>.yml
$ faas-cli push -f hello-world.yml
# faas-cli deploy -f <function>.yml
$ faas-cli deploy -f hello-world.yml
# faas-cli up -f <function>.yml
$ faas-cli up -f hello-world.yml
# faas-cli invoke <function>
$ faas-cli invoke hello-world
# Using cURL
curl http://192.168.50.2:8080/function/hello-world
# echo "<some-data>" | faas-cli invoke <function>
$ echo "Hi there!" | faas-cli invoke hello-world
# Using cURL
curl http://192.168.50.2:8080/function/hello-world -d "Hi there!"
A user interface is available at http://192.168.50.2:8080/ui/
You can Deploy and Invoke new functions from there.
To delete the virtual machine, run the following command:
$ vagrant destroy -f