### Install OpenFaaS Edge with Custom DNS and Remote Registry Source: https://docs.openfaas.com/edge/airgap Example installation command for OpenFaaS Edge, using a custom DNS server and assuming a remote registry is available. ```bash sudo /usr/local/bin/faasd install \ --dns-server 10.0.0.1 ``` -------------------------------- ### Install OpenFaaS Edge with Custom DNS and Pull Policy Source: https://docs.openfaas.com/edge/airgap Example installation command for OpenFaaS Edge on an air-gapped system, specifying a custom DNS server and a pull policy for images restored to the containerd library. ```bash sudo /usr/local/bin/faasd install \ --dns-server 127.0.0.53 \ --pull-policy=IfNotPresent ``` -------------------------------- ### Go Module Dependency Example Source: https://docs.openfaas.com/languages/go Shows how a Go module's dependency is recorded in the go.mod file after running `go get`. This example includes an indirect dependency. ```go module handler/function go 1.18 require golang.org/x/crypto v0.13.0 // indirect ``` -------------------------------- ### Get Help for faas-cli build Source: https://docs.openfaas.com/cli/build Run this command to view all available options and examples for the `faas-cli build` command. ```bash faas-cli build --help ``` -------------------------------- ### Install apache2-utils or httpd-tools Source: https://docs.openfaas.com/edge/builder Install the necessary utility for creating password files. Use apt for Debian-based systems and dnf for RHEL-based systems. ```bash # On Debian run: sudo apt install apache2-utils # On RHEL run: sudo dnf install httpd-tools ``` -------------------------------- ### Install QEMU User Static Source: https://docs.openfaas.com/cli/build Install QEMU utilities to enable cross-compilation for ARM architectures. This command should be run on your local machine, not on the faasd instance. ```bash docker run --rm --privileged \ multiarch/qemu-user-static \ --reset -p yes ``` -------------------------------- ### Install cron-connector with arkade Source: https://docs.openfaas.com/reference/cron Use arkade for a quick installation of the cron-connector during development or testing. Set 'openfaasPro=true' for OpenFaaS Pro deployments. ```bash arkade install cron-connector ``` ```bash arkade install cron-connector \ --set openfaasPro=true ``` -------------------------------- ### Install PHP extensions with custom script Source: https://docs.openfaas.com/languages/php Customize the PHP function image by adding or compiling extensions using the `php-extension.sh` script. This example shows how to install `pdo_mysql` and compile the Phalcon extension. ```bash #!/bin/sh echo "Installing PHP extensions" docker-php-ext-install pdo_mysql # Install Phalcon PHALCON_VERSION=3.4.0 PHALCON_EXT_PATH=php7/64bits set -xe && \ # Compile Phalcon curl -LO https://github.com/phalcon/cphalcon/archive/v${PHALCON_VERSION}.tar.gz && \ tar xzf ${PWD}/v${PHALCON_VERSION}.tar.gz && \ docker-php-ext-install -j $(getconf _NPROCESSORS_ONLN) ${PWD}/cphalcon-${PHALCON_VERSION}/build/${PHALCON_EXT_PATH} && \ # Remove all temp files rm -r \ ${PWD}/v${PHALCON_VERSION}.tar.gz \ ${PWD}/cphalcon-${PHALCON_VERSION} ``` -------------------------------- ### Download and install arkade Source: https://docs.openfaas.com/tutorials/local-kind-registry Use these commands to download and install the arkade CLI tool. You can choose to install it manually or with sudo privileges. ```bash # Download only, install yourself with sudo $ curl -sLS https://get.arkade.dev | sh ``` ```bash # Download and install $ curl -sLS https://get.arkade.dev | sudo sh ``` -------------------------------- ### Install CA Certificates during Build Source: https://docs.openfaas.com/reference/yaml This example demonstrates how to include `ca-certificates` as a build option in your stack.yml file. This ensures that the necessary certificates are installed in the Docker image, which can be crucial for making secure network requests from your function. ```yaml build_options: - ca-certificates ``` -------------------------------- ### Install arkade Source: https://docs.openfaas.com/cli/install Use this command to install arkade, a tool for easily installing DevOps and Kubernetes tools. ```bash curl -sSL https://get.arkade.dev | sudo -E sh ``` -------------------------------- ### Install OpenFaaS with Arkade Source: https://docs.openfaas.com/tutorials/local-kind-registry Install OpenFaaS Pro using arkade, providing a license file for enterprise features. Ensure your license is located at ~/.openfaas/LICENSE. ```bash $ arkade install openfaas --license-file ~/.openfaas/LICENSE ``` -------------------------------- ### Connect to PostgreSQL Source: https://docs.openfaas.com/openfaas-pro/postgres-events Connect to your PostgreSQL instance using `psql` to test the setup. ```bash PGPASSWORD=passwd psql -U postgres -h 127.0.0.1 ``` -------------------------------- ### Install Downloaded RPM Dependencies Source: https://docs.openfaas.com/edge/airgap Install the previously downloaded RPM packages and their dependencies on the air-gapped machine. ```bash sudo dnf install --disablerepo="*" ./rpm/*.rpm ``` -------------------------------- ### Download RHEL-like Installation Bundle Source: https://docs.openfaas.com/edge/airgap Use arkade to download the OpenFaaS Edge RPM installation bundle to the current directory. ```bash arkade oci install --path . ghcr.io/openfaasltd/faasd-pro-rpm:latest ``` -------------------------------- ### Install OpenFaaS Edge with gVisor Source: https://docs.openfaas.com/edge/gvisor Use this command during a new OpenFaaS Edge installation to enable the gVisor runtime. ```bash faasd install --gvisor ``` -------------------------------- ### Install OpenFaaS Edge with Custom DNS Source: https://docs.openfaas.com/edge/airgap Install OpenFaaS Edge, specifying a custom DNS server using the --dns-server flag. ```bash sudo faasd install --dns-server 127.0.0.53 ``` -------------------------------- ### Install Caddy with arkade Source: https://docs.openfaas.com/edge/tls Installs Caddy using the arkade package manager. Ensure you have arkade installed first. ```bash curl -sLS https://get.arkade.dev | sudo sh arkade system install caddy ``` -------------------------------- ### Create and start KinD cluster Source: https://docs.openfaas.com/tutorials/local-kind-ingress Create a KinD cluster named 'openfaas' using the specified configuration file. ```bash kind create cluster --name openfaas --config kind-config.yaml ``` -------------------------------- ### Deploy Function (Example) Source: https://docs.openfaas.com/reference/rest-api This example shows how to deploy a function using the `faas-cli` which interacts with the REST API. It demonstrates passing the namespace in the request body for a PUT operation. ```APIDOC ## PUT /system/functions ### Description Deploys or updates a function. This example uses `faas-cli` to illustrate the process, showing namespace handling in the request body. ### Method PUT ### Endpoint /system/functions ### Parameters #### Request Body - **service** (string) - Required - The name of the function service. - **image** (string) - Required - The Docker image for the function. - **namespace** (string) - Required - The namespace to deploy the function into. - **envProcess** (string) - Optional - The command to run as the process. - **labels** (object) - Optional - Key-value pairs for function labels. - **annotations** (object) - Optional - Key-value pairs for function annotations. ### Request Example ```bash FAAS_DEBUG=1 faas-cli store deploy -n alex figlet PUT http://127.0.0.1:8080/system/functions Content-Type: [application/json] {"service":"figlet","image":"ghcr.io/openfaas/figlet:latest","namespace":"alex","envProcess":"figlet","labels":{},"annotations":{}} ``` ### Response #### Success Response (200) Indicates successful deployment or update of the function. ``` -------------------------------- ### Install kubectl using arkade Source: https://docs.openfaas.com/tutorials/local-kind-registry Installs the kubectl command-line tool, which is used to interact with your Kubernetes cluster. ```bash $ arkade get kubectl ``` -------------------------------- ### Install OpenFaaS CE with arkade Source: https://docs.openfaas.com/deployment/kubernetes Use arkade to quickly install the Community Edition of OpenFaaS. This is the recommended method for most users. ```bash curl -SLsf https://get.arkade.dev/ | sh arkade install openfaas-ce ``` -------------------------------- ### Install airfaas CLI plugin Source: https://docs.openfaas.com/openfaas-pro/airgap Installs the airfaas CLI plugin. This is a prerequisite for using airfaas commands. ```bash faas-cli plugin get airfaas ``` -------------------------------- ### Perform Final OpenFaaS Edge Installation Source: https://docs.openfaas.com/edge/airgap Execute the final installation command for OpenFaaS Edge. ```bash sudo -E faasd install ``` -------------------------------- ### Example: Scaling up with target proportion Source: https://docs.openfaas.com/architecture/autoscaling Demonstrates how the autoscaler calculates the number of desired replicas when the total load is high and a target proportion is used. This example shows scaling from 1 to 2 replicas. ```plaintext total load = 90 mean per pod = 90 / 1 = 90 2 = ceil( 1 * ( 90 / ( 100 * 0.7 ) ) ) ``` -------------------------------- ### Install faas-cli with Bash (non-root) Source: https://docs.openfaas.com/cli/install Download the faas-cli binary into the current directory without root privileges. Installation instructions will be printed after download. ```bash curl -sSL https://cli.openfaas.com | sh ``` -------------------------------- ### Install OpenFaaS Edge on Debian-based Systems Source: https://docs.openfaas.com/edge/airgap Install the OpenFaaS Edge package using dpkg after transferring the .deb file to the air-gapped machine. ```bash sudo dpkg -i ./openfaas-edge-*-amd64.deb ``` -------------------------------- ### Example Standard Log Output Source: https://docs.openfaas.com/cli/logs An example of a log entry from the `nodeinfo` function, showing the standard format with a timestamp, function name, instance ID, and message. ```text 2019-07-21 07:57:14.437219758 +0000 UTC nodeinfo (nodeinfo-867cc95845-p9882) 2019/07/21 07:57:14 Wrote 92 Bytes - Duration: 0.121959 seconds ``` -------------------------------- ### Download Debian Installation Bundle Source: https://docs.openfaas.com/edge/airgap Use arkade to download the OpenFaaS Edge Debian installation bundle to the current directory. ```bash arkade oci install --path . ghcr.io/openfaasltd/faasd-pro-debian:latest ``` -------------------------------- ### Install WSL Utility for Browser Redirection Source: https://docs.openfaas.com/openfaas-pro/sso/cli For WSL users, install the `wslu` package to enable browser redirection. This ensures that authentication prompts open on your Windows host and results return to WSL. ```bash sudo apt update -qy && sudo apt install -qy wslu --no-install-recommends ``` -------------------------------- ### Example: Load distribution after scaling Source: https://docs.openfaas.com/architecture/autoscaling Shows how the load is distributed across replicas after scaling up and how the autoscaler re-evaluates the desired number of replicas. This example demonstrates the load per pod decreasing. ```plaintext mean per pod = 25 / 3 = 8.33 5 = ceil( 3 * ( 8.33 / 5 * 1 ) ) ``` -------------------------------- ### Install OpenFaaS with ClusterRole Source: https://docs.openfaas.com/reference/namespaces Install OpenFaaS with the necessary ClusterRole permissions to manage multiple namespaces. This is a prerequisite for enabling the multi-namespace feature. ```bash arkade install openfaas --clusterrole ``` -------------------------------- ### Install OpenFaaS Edge (faasd-pro) Source: https://docs.openfaas.com/deployment/edge Installs the OpenFaaS Edge (faasd-pro) commercial distribution using a utility script. This script fetches the latest version and makes it executable. ```bash curl -sLSf \ https://raw.githubusercontent.com/openfaas/faasd/refs/heads/master/hack/install-edge.sh \ -o install-edge.sh && \ chmod +x install-edge.sh sudo -E ./install-edge.sh ``` -------------------------------- ### Install airfaas CLI plugin Source: https://docs.openfaas.com/edge/airgap Download the `airfaas` CLI plugin to assist with image management for air-gapped environments. ```bash faas-cli plugin get airfaas ``` -------------------------------- ### Example: Scaling up based on load Source: https://docs.openfaas.com/architecture/autoscaling Illustrates the calculation for scaling up a function when the current load exceeds the target load. This example shows scaling from 1 to 3 replicas. ```plaintext mean per pod = 15 / 1 3 = ceil ( 1 * ( 15 / 5 * 1 ) ) ``` -------------------------------- ### SQL for PostgreSQL Example Source: https://docs.openfaas.com/languages/python SQL commands to create a database and table, and insert initial data for testing PostgreSQL integration. ```sql CREATE DATABASE main; \c main; CREATE TABLE users ( name TEXT, ); -- Insert the original Postgresql author's name into the test table: INSERT INTO users (name) VALUES ('Michael Stonebraker'); ``` -------------------------------- ### Install arkade for MacOS/Linux Source: https://docs.openfaas.com/deployment/kubernetes Installs the arkade CLI tool, which is recommended for deploying OpenFaaS and other related software to Kubernetes. This command is for MacOS and Linux systems. ```bash # For MacOS / Linux: curl -SLsf https://get.arkade.dev/ | sudo sh ``` -------------------------------- ### List Available Templates Source: https://docs.openfaas.com/cli/templates Use this command to view all available templates in the default store. It shows template names, whether they are recommended, and a brief description. ```bash $ faas-cli template store list NAME RECOMMENDED DESCRIPTION SOURCE bash-streaming [x] openfaas-incubator Bash Streaming template dockerfile [x] openfaas Classic Dockerfile template dotnet8-csharp [x] openfaas C# template using WebApplication golang-middleware [x] openfaas HTTP middleware interface in Go java11-vert-x [x] openfaas Java 11 Vert.x template node22 [x] openfaas HTTP-based Node 22 template php8 [x] openfaas Classic PHP 8 template python3-http [x] openfaas Python 3 with Flask and HTTP python3-http-debian [x] openfaas Python 3 with Flask and HTTP based on Debian ruby-http [x] openfaas Ruby 2.4 HTTP template ``` -------------------------------- ### List Functions in a Specific Namespace (GET) Source: https://docs.openfaas.com/reference/rest-api When using OpenFaaS for Enterprises, you can specify a namespace for GET operations using the `namespace` query parameter. This example lists functions in the 'alex' namespace. ```bash FAAS_DEBUG=1 faas-cli list -n alex GET http://127.0.0.1:8080/system/functions?namespace=alex ``` -------------------------------- ### Install NATS CLI using Arkade Source: https://docs.openfaas.com/openfaas-pro/jetstream Install the NATS command-line interface tool. This tool is required for managing NATS streams, including deleting them to reset queues. ```bash arkade get nats ``` -------------------------------- ### Install npm packages for Node.js function Source: https://docs.openfaas.com/languages/node To add external dependencies like `axios` to your Node.js function, navigate to the function's directory and use `npm install --save`. This example shows installing `axios` after creating a new function named 'http-req'. ```bash faas-cli new --lang node22 http-req cd http-req npm install --save axios ``` -------------------------------- ### Example Builder API Response with Duration Source: https://docs.openfaas.com/openfaas-pro/builder An example of a successful build response from the OpenFaaS builder API, including build logs, the image name, and the total duration in seconds. ```json { "log": [ "2022-06-23T09:10:12Z [ship 15/16] RUN npm test 0.35s", "2022-06-23T09:10:13Z [ship 16/16] WORKDIR /home/app/", "2022-06-23T09:10:13Z [ship 16/16] WORKDIR /home/app/ 0.09s", "2022-06-23T09:10:13Z exporting to image", "2022-06-23T09:11:06Z pushing manifest for ttl.sh/openfaas-image:1h@sha256:b077f553245c09d789980d081d33d46b93a23c24a5ec0a9c3c26be2c768db93e 0", "2022-06-23T09:11:09Z pushing manifest for ttl.sh/openfaas-image:1h@sha256:b077f553245c09d789980d081d33d46b93a23c24a5ec0a9c3c26be2c768db93e 0", "2022-06-23T09:10:13Z exporting to image 5.18s" ], "image": "ttl.sh/openfaas-image:1h", "status": "success", "duration": 0.843 } ``` -------------------------------- ### Install faasd CE Source: https://docs.openfaas.com/deployment/edge Clone the faasd repository and run the installation script to set up faasd CE for non-commercial use. This method is suitable for individuals and requires a stable internet connection. ```bash git clone https://github.com/openfaas/faasd --depth=1 cd faasd ./hack/install.sh ``` -------------------------------- ### Create Example Function with Scale to Zero Source: https://docs.openfaas.com/openfaas-pro/scale-to-zero Create a new OpenFaaS function using the golang-middleware template and configure it to scale to zero with a specified duration. ```bash export OPENFAAS_PREFIX=ttl.sh/daily-job:1h faas-cli new --lang golang-middleware daily-job ``` -------------------------------- ### Get OpenFaaS Info Source: https://docs.openfaas.com/deployment/kubernetes Retrieves information about your OpenFaaS installation using arkade. This command is useful for checking the status and configuration. ```bash arkade info openfaas ``` -------------------------------- ### Get faas-cli and Port-Forward Gateway Source: https://docs.openfaas.com/deployment/kubernetes Installs the faas-cli and sets up a port-forward to the OpenFaaS gateway. This is useful for interacting with your OpenFaaS deployment locally. ```bash arkade get faas-cli kubectl rollout status -n openfaas deploy/gateway kubectl port-forward -n openfaas svc/gateway 8080:8080 & ``` -------------------------------- ### GitLab CI/CD Pipeline for OpenFaaS Deployment Source: https://docs.openfaas.com/openfaas-pro/iam/gitlab-federation Example `.gitlab-ci.yml` to deploy to OpenFaaS. It obtains an ID token, installs the `faas-cli pro` plugin, and authenticates to the OpenFaaS gateway. ```yaml stages: - build services: - docker:dind cache: key: ${CI_COMMIT_REF_SLUG} # i.e. master paths: - ./faas-cli - ./template build_job: stage: build image: docker:latest variables: OPENFAAS_URL: https://gw.example.com script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - apk add --no-cache git curl - if [ -f "./faas-cli" ] ; then cp ./faas-cli /usr/local/bin/faas-cli || 0 ; fi - if [ ! -f "/usr/local/bin/faas-cli" ] ; then apk add --no-cache curl git && curl -sSL https://cli.openfaas.com | sh && chmod +x /usr/local/bin/faas-cli && cp /usr/local/bin/faas-cli ./faas-cli ; fi - faas-cli plugin get pro - faas-cli pro auth --token=$ID_TOKEN_1 - faas-cli list -n dev - faas-cli ns - faas-cli store deploy -n dev printer --name p1 id_tokens: ID_TOKEN_1: aud: https://gw.example.com ``` -------------------------------- ### List Functions (Basic Auth) Source: https://docs.openfaas.com/reference/rest-api This example demonstrates how to list all functions using basic authentication with the root user account. ```APIDOC ## GET /system/functions ### Description Lists all deployed functions in the OpenFaaS system. ### Method GET ### Endpoint /system/functions ### Parameters #### Query Parameters - **namespace** (string) - Optional - The namespace to list functions from. ### Request Example ```bash export HOST="127.0.0.1:8080" export PASSWORD="" curl -s \ http://admin:$PASSWORD@$HOST/system/functions ``` ### Response #### Success Response (200) - **functions** (array) - A list of function objects. - **name** (string) - The name of the function. - **image** (string) - The Docker image used by the function. - **invocation_url** (string) - The URL to invoke the function. - **handler** (string) - The handler used by the function. - **lang** (string) - The language of the function. - **secrets** (array) - A list of secrets used by the function. - **environment** (object) - Environment variables for the function. #### Response Example ```json [ { "name": "my-function", "image": "my-image:latest", "invocation_url": "http://127.0.0.1:8080/function/my-function.openfaas-fn", "handler": "my-handler", "lang": "python3", "secrets": [], "environment": {} } ] ``` ``` -------------------------------- ### Local Testing Setup for Authenticated Functions Source: https://docs.openfaas.com/languages/node Sets up the local environment to test an authenticated function by copying the secret token to the expected directory. Use `faas-cli local-run` to start the function locally. ```bash mkdir -p .secrets cp node-fn-token.txt .secrets/node-fn-token faas-cli local-run -f node-fn.yml ``` -------------------------------- ### Enable Pro plugin with GitHub Source: https://docs.openfaas.com/cli/install Enable the Pro plugin by authenticating via GitHub. This process opens a browser for device challenge completion. ```bash faas-cli pro enable ``` -------------------------------- ### Install cert-manager Source: https://docs.openfaas.com/reference/tls-openfaas Installs the cert-manager operator using arkade. Ensure arkade is installed first. ```bash $ arkade install cert-manager ``` -------------------------------- ### Install OpenFaaS Edge RPM Package Source: https://docs.openfaas.com/edge/airgap Install the OpenFaaS Edge RPM package after all its dependencies have been installed. ```bash sudo dnf install openfaas-edge-*.rpm ``` -------------------------------- ### List Available Templates Source: https://docs.openfaas.com/languages/custom Run this command to view the templates available in the current directory. This helps in selecting the correct language/framework for your function. ```bash faas-cli new --list ``` -------------------------------- ### Configure Caddyfile for OpenFaaS Gateway Source: https://docs.openfaas.com/edge/tls Sets up Caddy to proxy traffic to the OpenFaaS gateway. Replace example.com with your domain. ```plaintext { email example.com gateway.example.com { reverse_proxy localhost:8080 } ``` -------------------------------- ### Execute the KinD cluster creation script Source: https://docs.openfaas.com/tutorials/local-kind-registry Make the cluster creation script executable and then run it to provision your KinD cluster with a local registry. ```bash $ chmod +x ./kind-with-registry.sh $ ./kind-with-registry.sh ``` -------------------------------- ### Install OpenFaaS Edge RPM Package Source: https://docs.openfaas.com/deployment/edge Installs OpenFaaS Edge on RHEL-like systems using an RPM package. First, the package is downloaded using `arkade oci install`, then installed with `dnf`. ```bash arkade oci install --path . ghcr.io/openfaasltd/faasd-pro-rpm:latest ``` ```bash sudo dnf install openfaas-edge-*.rpm ``` -------------------------------- ### List All Templates from Store Source: https://docs.openfaas.com/languages/custom Execute this command to see all available templates, including community-contributed ones, from the OpenFaaS template store. Note that community templates may require due diligence for maintenance status. ```bash faas-cli template store list ``` -------------------------------- ### Build and Run a Go Function Locally Source: https://docs.openfaas.com/deployment/troubleshooting Create, build, and run a Go function locally for testing purposes. This example demonstrates using `faas-cli` to create a new function, build it, and then run it using Docker. ```bash faas-cli new --lang golang-middleware test-this faas-cli build -f test-this.yml docker run -p 8081:8080 \ --rm \ --name test-this \ -ti test-this:latest ``` -------------------------------- ### Install Required Packages on RHEL-like Systems Source: https://docs.openfaas.com/edge/airgap Ensure runc and iptables-services are installed on RHEL-like systems before installing OpenFaaS Edge. ```bash sudo dnf install runc iptables-services ``` -------------------------------- ### Example of Function Handler Folder Structure Source: https://docs.openfaas.com/reference/yaml Illustrates the directory structure of a function's build folder after including common, data, and models directories via the 'copy' configuration. ```text build └── hello ├── Dockerfile ├── function │   ├── __init__.py │   │   └── ... │   ├── models │   │   └── ... │   ├── data │   │   └── ... │   ├── common │   │   └── ... │   ├── handler.py │   └── requirements.txt ├── index.py ├── requirements.txt └── template.yml ``` -------------------------------- ### Deploy and List Functions Source: https://docs.openfaas.com/deployment/kubernetes Deploys the 'nodeinfo' function from the store and lists all deployed functions. This is a quick way to test your OpenFaaS setup. ```bash faas-cli store deploy nodeinfo faas-cli list ``` -------------------------------- ### Install Required Packages on Debian-based Systems Source: https://docs.openfaas.com/edge/airgap Ensure essential packages like runc, bridge-utils, and iptables are installed before proceeding with the OpenFaaS Edge installation on Debian-based systems. ```bash sudo apt update && \ sudo apt install runc bridge-utils iptables iptables-persistent ``` -------------------------------- ### Install Profile CRD for OpenFaaS on Kubernetes Source: https://docs.openfaas.com/reference/profiles Apply this YAML to install the Custom Resource Definition (CRD) for Profiles when installing OpenFaaS on Kubernetes, if not handled automatically by the Helm chart. ```yaml # This is a placeholder for the actual YAML content of the CRD. # The actual CRD definition would be provided in the OpenFaaS documentation. # Example structure: # apiVersion: apiextensions.k8s.io/v1 # kind: CustomResourceDefinition # metadata: # name: profiles.openfaas.com # spec: # group: openfaas.com # versions: # - name: v1alpha1 # served: true # storage: true # scope: Namespaced # names: # plural: profiles # singular: profile # kind: Profile # shortNames: # - prof ``` -------------------------------- ### Install faas-cli with Curl Source: https://docs.openfaas.com/tutorials/first-python-function Installs the OpenFaaS CLI on Linux or macOS using a curl command. ```bash $ curl -sSL https://cli.openfaas.com | sudo sh ``` -------------------------------- ### OpenFaaS Stack Configuration with PostgreSQL Source: https://docs.openfaas.com/languages/python Example stack.yml configuration for a function requiring PostgreSQL, including language, handler, image, and build options for 'libpq'. ```yaml version: 1.0 provider: name: openfaas gateway: http://127.0.0.1:8080 functions: pgfn: lang: python3-http-debian handler: ./pgfn image: pgfn:latest build_options: - libpq ``` -------------------------------- ### Install OpenTelemetry Packages for Node.js Source: https://docs.openfaas.com/languages/node Install the necessary OpenTelemetry packages for zero-code instrumentation in your Node.js template. ```bash npm install --save @opentelemetry/api npm install --save @opentelemetry/auto-instrumentations-node ``` -------------------------------- ### List and Deploy Functions for ARM Source: https://docs.openfaas.com/deployment/kubernetes Use these commands to list and deploy functions from the OpenFaaS Function Store, specifying the ARM platform. Ensure OPENFAAS_URL is set. ```bash export OPENFAAS_URL=http://IP:8080/ faas-cli store list --platform armhf faas-cli store deploy NAME --platform armhf ``` ```bash export OPENFAAS_URL=http://IP:8080/ faas-cli store list --platform arm64 faas-cli store deploy NAME --platform arm64 ``` -------------------------------- ### Install faas-cli with arkade Source: https://docs.openfaas.com/cli/install Install the faas-cli using arkade. This command can also be run again to update the CLI. ```bash arkade get faas-cli ``` -------------------------------- ### View OpenFaaS Gateway Logs Source: https://docs.openfaas.com/deployment/troubleshooting Check the logs for the `gateway` deployment in the `openfaas` namespace to identify startup errors. ```bash kubectl logs -n openfaas deploy/gateway ``` -------------------------------- ### Example JSON log output Source: https://docs.openfaas.com/reference/rest-api This is an example of the JSON formatted log output when requesting logs from a function. ```json {"name":"env","namespace":"","instance":"env-5b6d68d94c-qqdtj","timestamp":"2023-07-04T16:32:22.223912519Z","text":"2023/07/04 16:32:22 Version: 0.1.4\tSHA: 86e85231a20df03bc9187a31c400f4bbc4e2b9ba\n"} {"name":"env","namespace":"","instance":"env-5b6d68d94c-qqdtj","timestamp":"2023-07-04T16:32:22.223947899Z","text":"2023/07/04 16:32:22 Timeouts: read: 5s, write: 5s hard: 0s.\n"} {"name":"env","namespace":"","instance":"env-5b6d68d94c-qqdtj","timestamp":"2023-07-04T16:32:22.223954179Z","text":"2023/07/04 16:32:22 Listening on port: 8080\n"} {"name":"env","namespace":"","instance":"env-5b6d68d94c-qqdtj","timestamp":"2023-07-04T16:32:22.223983229Z","text":"2023/07/04 16:32:22 Writing lock-file to: /tmp/.lock\n"} {"name":"env","namespace":"","instance":"env-5b6d68d94c-qqdtj","timestamp":"2023-07-04T16:32:22.223987809Z","text":"2023/07/04 16:32:22 Metrics listening on port: 8081\n"} {"name":"env","namespace":"","instance":"env-5b6d68d94c-qqdtj","timestamp":"2023-07-04T16:32:23.380573646Z","text":"2023/07/04 16:32:23 Forking fprocess.\n"} {"name":"env","namespace":"","instance":"env-5b6d68d94c-qqdtj","timestamp":"2023-07-04T16:32:23.382405318Z","text":"2023/07/04 16:32:23 Wrote 932 Bytes - Duration: 0.001823s\n"} ``` -------------------------------- ### Publish and deploy function in one step Source: https://docs.openfaas.com/openfaas-pro/builder Combines the build and deployment process into a single command. It first builds the function image using the remote builder and then deploys it to the cluster. ```bash faas-cli up --remote-builder http://127.0.0.1:8081/build \ --payload-secret $HOME/.openfaas/payload.txt ``` -------------------------------- ### Install ingress-nginx using arkade Source: https://docs.openfaas.com/tutorials/local-kind-ingress Install the ingress-nginx controller into your Kubernetes cluster using the arkade CLI tool. ```bash arkade install ingress-nginx ``` -------------------------------- ### Stack.yml for Function Deployment with Git SHA Source: https://docs.openfaas.com/openfaas-pro/dashboard Example of a stack.yml configuration for deploying a function, specifically showing how to use environment substitution for the Git SHA. This allows dynamic updates of the SHA during CI/CD. ```yaml functions: cows: lang: golang-middleware handler: ./cows image: alexellis2/cows:0.1 labels: com.openfaas.git-sha: ${GIT_SHA:-dev} ``` -------------------------------- ### Install OpenFaaS CLI Source: https://docs.openfaas.com/tutorials/CLI-with-node Installs the latest version of the OpenFaaS CLI using curl. This command requires sudo privileges. ```bash $ curl -sL https://cli.openfaas.com | sudo sh ``` -------------------------------- ### Deploy OpenFaaS Function Source: https://docs.openfaas.com/tutorials/first-python-function Deploys the 'hello-python' function to the OpenFaaS gateway using the provided YAML configuration. ```bash $ faas-cli deploy -f ./hello-python.yml ``` -------------------------------- ### Install Jenkins with Helm Source: https://docs.openfaas.com/reference/cicd/jenkins Use Helm to install Jenkins on a Kubernetes cluster. Ensure RBAC is enabled for proper permissions. ```bash $ helm install --name cicd stable/jenkins --set rbac.install=true ``` -------------------------------- ### List Functions with Basic Authentication Source: https://docs.openfaas.com/reference/rest-api Use this command to list all functions when using Basic Authentication with the root user account. Ensure the HOST and PASSWORD environment variables are set correctly. ```bash export HOST="127.0.0.1:8080" export PASSWORD="" curl -s \ http://admin:$PASSWORD@$HOST/system/functions ``` -------------------------------- ### Deploying and Invoking with Debug Output Source: https://docs.openfaas.com/cli/logs This sequence demonstrates deploying a function with debug output enabled and then invoking it, showing how to capture and filter the logs. ```bash faas-cli store deploy SentimentAnalysis --env write_debug=true echo "i like code" | faas-cli invoke sentimentanalysis echo "i like functions" | faas-cli invoke sentimentanalysis echo "i like containers" | faas-cli invoke sentimentanalysis ``` -------------------------------- ### Configure OpenFaaS Dashboard in values.yaml Source: https://docs.openfaas.com/openfaas-pro/dashboard Example configuration for enabling and setting up the OpenFaaS Dashboard within the `values.yaml` file for the OpenFaaS Helm chart. It includes enabling the dashboard, setting a public URL, and specifying the signing key secret. ```yaml dashboard: enabled: true publicURL: https://dashboard.example.com # Name of signing key secret for sessions. # Can be left blank for development deployments. signingKeySecret: "dashboard-jwt" ``` -------------------------------- ### Install Bash Completion for MacOS Source: https://docs.openfaas.com/cli/completion Install bash-completion@2 and configure your environment for Bash completion on MacOS. Requires Bash 4.1+. ```bash $ brew install bash-completion@2 ``` ```bash export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d" [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" ``` ```bash $ echo 'source <(faas-cli completion --shell bash)' >>~/.bashrc ``` ```bash $ faas-cli completion --shell bash > /etc/bash_completion.d/faas-cli ``` -------------------------------- ### Install faas-cli with Homebrew Source: https://docs.openfaas.com/cli/install Install the faas-cli using Homebrew on macOS. Note that the Homebrew version may lag behind the latest release. ```bash brew install faas-cli ``` -------------------------------- ### Build, Push, and Deploy Function Source: https://docs.openfaas.com/tutorials/local-kind-registry Use the 'faas-cli up' command to build the function's Docker image, push it to the configured registry, and deploy it to Kubernetes in a single step. ```bash faas-cli up -f pydict.yml ``` -------------------------------- ### Build, Deploy, and Invoke Function Source: https://docs.openfaas.com/openfaas-pro/scale-to-zero Build the function, push its image, and deploy it to your OpenFaaS Pro cluster. Then, invoke the function to test its deployment. ```bash # Build, push and deploy the function: faas-cli up -f daily-job.yml # Invoke the function: echo | faas-cli invoke daily-job ``` -------------------------------- ### Example OpenFaaS Pro Telemetry Output Source: https://docs.openfaas.com/deployment/pro This is an example of the JSON output you can expect when querying the telemetry endpoint, showing cluster and function statistics. ```json { "s": "0.0.2", "v": "0.5.61-8-gc2c68d17", "data": { "uptime": 5717804906149224, "license_email": "admin@example.com", "namespace": "openfaas", "operator_version": "0.5.61-8-gc2c68d17", "k8s_version": "v1.29.3+k3s1", "total_fns": 24, "total_namespaces": 4, "total_replicas": 20, "invocations_daily": 3.000266226477385, "seconds_daily": 0.014143783188987933 } } ``` -------------------------------- ### Set up self-hosted PostgreSQL with WAL mode Source: https://docs.openfaas.com/openfaas-pro/postgres-events Use Docker to run a PostgreSQL instance, modify its configuration for WAL mode, and restart it. ```bash docker run --rm --name pg -e POSTGRES_PASSWORD=passwd -p 5432:5432 -ti postgres:latest docker cp pg:/var/lib/postgresql/data/postgresql.conf postgresql.conf echo "wal_level = logical" | tee -a postgresql.conf echo "max_wal_senders = 10" | tee -a postgresql.conf echo "max_replication_slots = 5" | tee -a postgresql.conf docker cp postgresql.conf pg:/var/lib/postgresql/data/postgresql.conf docker restart pg ``` -------------------------------- ### Pre-create Secrets Folder and Secret Source: https://docs.openfaas.com/edge/preloading Create the secrets folder and a sample secret for a function in the 'openfaas-fn' namespace. ```bash mkdir -p /var/lib/faasd-provider/secrets/openfaas-fn echo "secret" | sudo tee /var/lib/faasd-provider/secrets/openfaas-fn/api-key ``` -------------------------------- ### Function Timeout Example (stack.yaml) Source: https://docs.openfaas.com/tutorials/expanded-timeouts Example of setting environment variables for function timeouts in `stack.yaml`. Note that `exec_timeout` should not exceed the gateway's `upstream_timeout`. ```yaml functions: job: environment: write_timeout: 5m1s read_timeout: 5m1s exec_timeout: 5m ``` -------------------------------- ### Configure Docker Build Context Source: https://docs.openfaas.com/openfaas-pro/builder Sets environment variables for the image registry and owner, then creates a configuration file for the Docker build. The 'platforms' key is optional and specifies the image platform. ```bash export REGISTRY=ttl.sh export OWNER=alexellis2 echo -n '{"image": "'$REGISTRY'/'$OWNER'/test-image-hello:0.1.0", "platforms": ["linux/amd64"]}' > com.openfaas.docker.config ``` -------------------------------- ### Printer Function Log Output Example Source: https://docs.openfaas.com/openfaas-pro/rabbitmq-events Example log output from the 'printer' function after receiving a message from RabbitMQ. Shows connector headers and the message payload. ```text faas-cli logs printer 2024-12-03T14:36:03Z X-Connector=[connector-sdk openfaasltd/rabbitmq-connector] 2024-12-03T14:36:03Z X-Topic=[queue1] 2024-12-03T14:36:03Z Accept-Encoding=[gzip] 2024-12-03T14:36:03Z Content-Type=[text/plain] 2024-12-03T14:36:03Z X-Call-Id=[d0ab9f9e-0c93-46b1-a4dd-695a037acb38] 2024-12-03T14:36:03Z 2024/12/03 14:36:03 POST / - 202 Accepted - ContentLength: 0B (0.0003s) 2024-12-03T14:36:03Z X-Forwarded-Host=[gateway.openfaas:8080] 2024-12-03T14:36:03Z X-Rabbitmq-Msg-Id=[1] 2024-12-03T14:36:03Z X-Start-Time=[1733236563468386644] 2024-12-03T14:36:03Z X-Forwarded-For=[10.42.0.13:55796] 2024-12-03T14:36:03Z X-Rabbitmq-Routing-Key=[queue1] 2024-12-03T14:36:03Z User-Agent=[openfaas-gateway/0.4.34] 2024-12-03T14:36:03Z 2024-12-03T14:36:03Z Hello, Task Queue! 2024-12-03T14:36:03Z ``` -------------------------------- ### JSON Log Format Example Source: https://docs.openfaas.com/cli/logs This example shows how to retrieve logs in JSON format using the `faas-cli logs` command with the `--format json` flag. ```bash $ faas-cli logs trove --format json ``` ```json {"name":"trove","namespace":"openfaas-fn","instance":"9174","timestamp":"2021-02-12T17:01:03.088068Z","text":"User requested \"Insiders Update: 1st Feb 2020 - Java, KubeCon, Istio, Crossplane and more!\""} ```