Servicemanagement in Netzen - Leischner
Praktikumsblatt 10 - Serverless Computing (part 2) by Yasodhara
Modupalli
OpenFaaS UI portal allows user to view the
list of functions and invoke them with a button click. In this
internship we first observe how to deploy and invoke function
from the OpenFaaS UI. In the next task, you will create a custom
function then deploy and invoke it using faas-cli
,
which will be added to the functions list in the UI.
Task 1 – Deploy a random function from store
- Open OpenFaaS UI portal in the browser with
OPENFAAS_URL
.
- Click on Deploy New
Function and select a function
from store list and click
Deploy.
- For example, select figlet
function and deploy. That
will be added to the list in the left panel of the portal.
Now, click on the function and wait until the
status changes to
Ready. Then,
invoke the function with an
input text. You will see the response in the
Response body section.
- Now list the deployed functions with the number of
invocations. Which command do you use for that?
- Which command do you use to invoke a function from
command line?
Task 2 – Dockerhub login and pull the scaffolding
language templates
- The function that we create now will be built as a
docker image and then deployed to cluster using OpenFaaS.
For that, we need to login to Docker from command line using
docker login
command.
- OpenFaaS supports various programming languages to
create functions. The supported languages are available as
templates. Before creating a function from template, we need
to pull the
templates from the GitHub.
Note:
Functions created using unsupported languages can be built
as dockerfile
.
- Which command is used to pull the templates using
faas-cli
? Which command lists the available
languages in templates?
Task 3 – Create a custom function and deploy
- To create a function use the command in the following
format:
faas-cli new --lang <language-name>
<function-name> --prefix="<your-docker-username-here>"
Note: If the language of your choice is not
available you can use dockerfile
template.
- The above command will create three files and
directory. Can you mention the directory structure with file
names?
- The contents of
<function-name>.yml
file should
meet the below specifications:
- The name of the function is represented by the
key under
functions
i.e,
<function-name>
.
- The language is represented by the
lang
field.
- The folder used to build from is called
handler
, this must be a folder not a file.
- The docker image to be used is under the field
image
.
Note: You can also
mention
<docker-username>
before
the image name under image
field in the
.yml
file if you forgot to add with the
--prefix=”<docker-username>”
tag.
- Change the contents of handler.xx file. Any values
returned to stdout will eventually be returned to the
calling program.
- Build and deploy the function with the command:
faas-cli up -f
<function-name>.yml
Note:
faas-cli up
command combines build, push, and deploy
commands of faas-cli
together. Alternatively,
you can use three commands one after another.
- Now invoke the function using
faas-cli
.
Which command did you use?
- Finally, you can check the functions list in
terminal with
faas-cli list
. Additionally, you
can also check in the UI portal and invoke
from
there.
- You can find out the hight-level information on
every invocation of your function from the container logs.
Which command will you use to trouble shoot the function
that you created above?
Optional Task:
OpenFaaS tracks metrics on your functions automatically using
Prometheus. The metrics can be turned into a useful dashboard
with free and Open-Source tools like
Grafana.
- Run Grafana in OpenFaaS kubernetes namespace.
Provide the commands used.
- Expose Grafana with a NodePort or use
port-forwarding method. Which command is used for that?
- After the service has been created open Grafana in
your browser with username
admin
and password
admin
. Now you can access the OpenFaaS
dashboard at $GRAFANA_URL
and monitor the
metrics.