This is a self-paced workshop for learning how to build, deploy and run serverless functions with OpenFaaS.
In this workshop you begin by deploying OpenFaaS to your laptop or a remote cluster with Docker for Mac or Windows. You will then kick the tires with the OpenFaaS UI, CLI and Function Store. After building, deploying an invoking your own Serverless Functions in Python you'll go on to cover topics such as: managing dependencies with pip, dealing with API tokens through secure secrets, monitoring functions with Prometheus, invoking functions asynchronously and chaining functions together to create applications. The labs culminate by having you create your very own GitHub bot which can respond to issues automatically. The same method could be applied by connecting to online event-streams through IFTTT.com - this will enable you to build bots, auto-responders and integrations with social media and IoT devices.
Finally the labs cover more advanced topics and give suggestions for further learning.
Translations
OpenFaaS along with these materials are provided for free and require time and effort to maintain.
- Become a sponsor for OpenFaaS on GitHub
We walk through how to install these requirements in Lab 1. Please do Lab 1 before you attend an instructor-led workshop.
- Functions will be written in Python, so prior programming or scripting experience is preferred
- Install the recommended code-editor / IDE VSCode
- For Windows install Git Bash
- Preferred OS: MacOS, Windows 10 Pro/Enterprise, Ubuntu Linux
Docker:
Note: As a last resort if you have an incompatible PC you can run the workshop on https://labs.play-with-docker.com/.
If you're taking an instructor-led workshops then a link will be shared to join the OpenFaaS Slack community. Use the designated channel for the workshop to discuss comments, questions and suggestions.
In Lab 1 you will pick your track and then throughout the labs look out for any special commands needed for the container orchestrator for your track.
You can also learn about Serverless on Kubernetes using OpenFaaS.
The recommendation from the OpenFaaS community is that you run Kubernetes in production, but all the knowledge you can is transferrable and functions do not have to be rebuilt.
- Install pre-requisites
- Set up a single-node cluster with Kubernetes
- Docker Hub account
- OpenFaaS CLI
- Deploy OpenFaaS
- Use the UI Portal
- Deploy via the Function Store
- Learn about the CLI
- Find metrics with Prometheus
- Scaffold or generate a new function
- Build the astronaut-finder function
- Add dependencies with
pip
- Troubleshooting: find the container's logs
- Troubleshooting: verbose output with
write_debug
- Use custom and third-party language templates
- Discover community templates using the Template Store
- Inject configuration through environmental variables
- At deployment using yaml
- Dynamically using HTTP context - querystring / headers etc
- Security: read-only filesystems
- Making use of logging
- Create Workflows
- Chaining functions on the client-side
- Call one function from another
Build
issue-bot
- an auto-responder for GitHub Issues
- Get a GitHub account
- Set up a tunnel with ngrok
- Create an webhook receiver
issue-bot
- Receive webhooks from GitHub
- Deploy SentimentAnalysis function
- Apply labels via the GitHub API
- Complete the function
- Generate and return basic HTML from a function
- Read and return a static HTML file from disk
- Collaborate with other functions
- Call a function synchronously vs asynchronously
- View the queue-worker's logs
- Use an
X-Callback-Url
with requestbin and ngrok
- Adjust timeouts with
read_timeout
- Accommodate longer running functions
- See auto-scaling in action
- Some insights on min and max replicas
- Discover and visit local Prometheus
- Execute and Prometheus query
- Invoke a function using curl
- Observe auto-scaling kicking in
- Adapt issue-bot to use a secret
- Create a Kubernetes secret with faas-cli
- Access the secret within the function
- Apply trust to functions using HMAC
You can start with the first lab Lab 1.
You can find how to stop and remove OpenFaaS here
If you're in an instructor-led workshop and have finished the labs you may want to go back through the labs and edit/alter the code and values or carry out some of your own experiments.
Here are some ideas for follow-on tasks / topics:
Try the multi-user, managed experience of OpenFaaS - either on the Community Cluster, or by hosting your own OpenFaaS Cloud.
Setup Jenkins, Google Cloud Build or GitLab and build and deploy your own functions using the OpenFaaS CLI:
The appendix contains some additional content.
Thanks to @iyovcheva, @BurtonR, @johnmccabe, @laurentgrangeau, @stefanprodan, @kenfdev, @templum & @rgee0 for contributing to, testing and translating the labs.