GitOps meets Serverless
With Flux and OpenFaaS
Alex Ellis (@alexellisuk)
CNCF Ambassador & Founder @ OpenFaaS Ltd
Agenda ⚡
• Serverless 1.0 vs 2.0
• OpenFaaS
• Template store ⌨
• Vs. Kubernetes
• Continuous deployment 🤓
• OpenFaaS Cloud
• Flux
@openfaas / @alexellisuk
Serverless & FaaS
• Easy to manage:
• Stateless
• Isomorphic
• Event-driven or REST
• Smaller
• Focus on code
Serverless 1.0 (Cloud Functions/FaaS)
Serverless 2.0
OpenFaaS - Simple, Secure, Serverless
• Founded in 2016 to “make
Serverless portable” 🎂

• Three values:
• Developer-focused
• Easy to operate
• Community-centric
> 21k stars
> 250 contributors
> 2.5k Slack
PLONK Stack
• Prometheus
• Linux/Linkerd
• OpenFaaS
• NATS
• Kubernetes
🤓

“But, I have a CKA/D, so why should I care?”
• A Node.js microservice for
Kubernetes
Adding a new service (the hard way)
Did we miss anything?
OpenFaaS: Template Store
handler.js (“node12”) stack.yml
• Memory / CPU limits
• Labels / Annotations
• Environment variables
• Secrets
Slide Title
SUBTITLE
• List

• List

• List

• List

◦ List

◦ List

▪ List

▪ List 

▪ List

▪ List

Install PLONK stack
curl https://dl.get-arkade.dev | sh
arkade install openfaas
ark
ade
Synchronous invocations
https://gw.example.com/function/generate-statement/
https://api.example.com/v1/generate-statement/
https://generate.example.com/
Asynchronous with NATS
GitOps for functions
1) CI -> checkout, build, push
2) CD -> test, deploy, canary
GitOps tooling (push)
• Push - event-driven
• Jenkins / Tekton
• GitLab
• OpenFaaS Cloud


Drift
More efficient - no lag
Incoming network access*
Push
Code &
Config
OpenFaaS Cloud 3) Checkout
Build & test
Push & deploy1) Authorize
2) Commit
OpenFaaS Cloud Demo
https://github.com/alexellis/gitops-webinar
OpenFaaS Cloud
• GitHub & GitLab integration
• Multi-user access OAuth2
• CI/CD
• Dashboards
• Builds, logs, metrics, health
• SealedSecret support
• Governance & teams
https://www.youtube.com/
watch?v=sD7hCwq3Gw0
GitOps tooling (pull)
• Pull - polling
• ArgoCD
• FluxCD
Pull
Code
Config
Builds
Higher complexity
Code + config repos
Flux install per repo
Easier to recover from disaster*
FluxCD & HelmOperator
https://github.com/stefanprodan/openfaas-flux
Install FluxCD & HelmOperator
GH_USER=${1:-alexellis}
GH_REPO=${2:-openfaas-flux}
GH_BRANCH=${3:-master}
GH_URL="git@github.com:${GH_USER}/${GH_REPO}"
helm upgrade -i flux fluxcd/flux --wait 
--namespace fluxcd 
--set git.url=${GH_URL} 
--set git.branch=${GH_BRANCH}
helm upgrade -i helm-operator fluxcd/helm-operator --wait 
--namespace fluxcd 
--set git.ssh.secretName=flux-git-deploy 
--set helm.versions=v3
FluxCD & HelmOperator
Deploy the OpenFaaS chart
apiVersion: helm.fluxcd.io/v1
kind: HelmRelease
metadata:
name: openfaas
namespace: openfaas
spec:
releaseName: openfaas
chart:
repository: https://openfaas.github.io/faas-netes/
name: openfaas
version: 5.4.0
values:
generateBasicAuth: true
serviceType: LoadBalancer
operator:
create: true
Create a new function in Go
$ faas-cli new --lang go generate-pdf
.
|—- generate-pdf/
|—- generate-pdf/handler.go
└—- generate-pdf.yml
package function
func Handle(req []byte) string {
return "Enjoy your PDF”
}
version: 1.0
provider:
name: openfaas
gateway: http://127.0.0.1:8080

functions:
generate-pdf:
lang: go
handler: ./generate-pdf
image: generate-pdf:latest
$ faas-cli build/push/deploy



# Or:
$ faas-cli up
Function CRD - from stack.yml
$ faas-cli generate -f generate-pdf apiVersion: openfaas.com/v1alpha2
kind: Function
metadata:
name: generate-pdf
spec:
name: generate-pdf
image: generate-pdf:latest
Function CRD - from store
$ faas-cli generate --from-store 
colorise
apiVersion: openfaas.com/v1alpha2
kind: Function
metadata:
name: colorise
spec:
name: colorise
image: alexellis2/openfaas-colorization:0.4.1
environment:
read_timeout: 60s
url_mode: "true"
write_debug: "false"
write_timeout: 60s
labels:
com.openfaas.ui.ext: jpg
Function CRD
apiVersion: openfaas.com/v1alpha2
kind: Function
metadata:
name: generate-pdf
spec:
name: generate-pdf
image: alexellis2/generate-pdf:latest
environment:
write_timeout: "10s"
# Create a new Function
$ faas-cli new --lang go 
generate-pdf

$ faas-cli generate 
-f generate-pdf.yml
# Or from Function Store
$ faas-cli generate 
--from-store colorise
GitOps to deploy functions
apiVersion: helm.fluxcd.io/v1
kind: HelmRelease
metadata:
name: functions
namespace: openfaas-fn
annotations:
fluxcd.io/ignore: "false"
fluxcd.io/automated: "false"
filter.fluxcd.io/certinfo: semver:~1.0
filter.fluxcd.io/podinfo: semver:~3.1
spec:
releaseName: functions
chart:
git: git@github.com:alexellis/openfaas-flux
ref: master
path: functions
values:
certinfo:
image: stefanprodan/certinfo:1.0.0
podinfo:
image: stefanprodan/podinfo:3.1.0
Function CRD
apiVersion: openfaas.com/v1alpha2
kind: Function
metadata:
name: podinfo
labels:
{{ include "functions.labels" . | indent 4 }}
spec:
name: podinfo
image: {{ .Values.podinfo.image }}
readOnlyRootFilesystem: true
annotations:
com.openfaas.health.http.initialDelay: 2s
com.openfaas.health.http.path: /healthz
labels:
com.openfaas.scale.min: "1"
com.openfaas.scale.max: "5"
environment:
PODINFO_PORT: "8080"
PODINFO_UI_COLOR: “#34577c"
Flux demo
GitOps conclusion ⚖
• FluxCD
• Pull-based (polling)
• Repo for config/code
• Flux per repo
• Limited GitHub/
GitLab integration (no
statuses)
• No ARM support
• Alternative
• Push-based (webhooks)
• Harder to recover
• 1 repo for config/code
• Tools can be shared
• Statuses and checks
• ARM support
In summary 💻
• Serverless 2.0 (w/Kubernetes)
• anything, anywhere, any scale
• Template Store
• reduce duplication, maintenance

• OpenFaaS Cloud (push)
• Serverless PaaS with GitOps
• FluxCD & HelmOperator (pull)
• CD for OpenFaaS & Functions with CRD
Connect & Learn 👋
• Docs & workshop
• Blog posts & tutorials
• Join the community on
Slack
https://openfaas.com/
Thank You!
@alexellisuk / @openfaas

GitOps meets Serverless

  • 1.
    GitOps meets Serverless WithFlux and OpenFaaS Alex Ellis (@alexellisuk) CNCF Ambassador & Founder @ OpenFaaS Ltd
  • 2.
    Agenda ⚡ • Serverless1.0 vs 2.0 • OpenFaaS • Template store ⌨ • Vs. Kubernetes • Continuous deployment 🤓 • OpenFaaS Cloud • Flux @openfaas / @alexellisuk
  • 3.
    Serverless & FaaS •Easy to manage: • Stateless • Isomorphic • Event-driven or REST • Smaller • Focus on code
  • 4.
    Serverless 1.0 (CloudFunctions/FaaS)
  • 5.
  • 7.
    OpenFaaS - Simple,Secure, Serverless • Founded in 2016 to “make Serverless portable” 🎂
 • Three values: • Developer-focused • Easy to operate • Community-centric > 21k stars > 250 contributors > 2.5k Slack
  • 8.
    PLONK Stack • Prometheus •Linux/Linkerd • OpenFaaS • NATS • Kubernetes
  • 9.
    🤓
 “But, I havea CKA/D, so why should I care?”
  • 10.
    • A Node.jsmicroservice for Kubernetes Adding a new service (the hard way) Did we miss anything?
  • 11.
    OpenFaaS: Template Store handler.js(“node12”) stack.yml • Memory / CPU limits • Labels / Annotations • Environment variables • Secrets
  • 13.
    Slide Title SUBTITLE • List
 •List
 • List
 • List
 ◦ List
 ◦ List
 ▪ List
 ▪ List 
 ▪ List
 ▪ List

  • 14.
    Install PLONK stack curlhttps://dl.get-arkade.dev | sh arkade install openfaas ark ade
  • 15.
  • 16.
  • 17.
    GitOps for functions 1)CI -> checkout, build, push 2) CD -> test, deploy, canary
  • 18.
    GitOps tooling (push) •Push - event-driven • Jenkins / Tekton • GitLab • OpenFaaS Cloud 
 Drift More efficient - no lag Incoming network access* Push Code & Config
  • 19.
    OpenFaaS Cloud 3)Checkout Build & test Push & deploy1) Authorize 2) Commit
  • 20.
  • 21.
    OpenFaaS Cloud • GitHub& GitLab integration • Multi-user access OAuth2 • CI/CD • Dashboards • Builds, logs, metrics, health • SealedSecret support • Governance & teams https://www.youtube.com/ watch?v=sD7hCwq3Gw0
  • 22.
    GitOps tooling (pull) •Pull - polling • ArgoCD • FluxCD Pull Code Config Builds Higher complexity Code + config repos Flux install per repo Easier to recover from disaster*
  • 23.
  • 24.
    Install FluxCD &HelmOperator GH_USER=${1:-alexellis} GH_REPO=${2:-openfaas-flux} GH_BRANCH=${3:-master} GH_URL="git@github.com:${GH_USER}/${GH_REPO}" helm upgrade -i flux fluxcd/flux --wait --namespace fluxcd --set git.url=${GH_URL} --set git.branch=${GH_BRANCH} helm upgrade -i helm-operator fluxcd/helm-operator --wait --namespace fluxcd --set git.ssh.secretName=flux-git-deploy --set helm.versions=v3
  • 25.
  • 26.
    Deploy the OpenFaaSchart apiVersion: helm.fluxcd.io/v1 kind: HelmRelease metadata: name: openfaas namespace: openfaas spec: releaseName: openfaas chart: repository: https://openfaas.github.io/faas-netes/ name: openfaas version: 5.4.0 values: generateBasicAuth: true serviceType: LoadBalancer operator: create: true
  • 27.
    Create a newfunction in Go $ faas-cli new --lang go generate-pdf . |—- generate-pdf/ |—- generate-pdf/handler.go └—- generate-pdf.yml package function func Handle(req []byte) string { return "Enjoy your PDF” } version: 1.0 provider: name: openfaas gateway: http://127.0.0.1:8080
 functions: generate-pdf: lang: go handler: ./generate-pdf image: generate-pdf:latest $ faas-cli build/push/deploy
 
 # Or: $ faas-cli up
  • 28.
    Function CRD -from stack.yml $ faas-cli generate -f generate-pdf apiVersion: openfaas.com/v1alpha2 kind: Function metadata: name: generate-pdf spec: name: generate-pdf image: generate-pdf:latest
  • 29.
    Function CRD -from store $ faas-cli generate --from-store colorise apiVersion: openfaas.com/v1alpha2 kind: Function metadata: name: colorise spec: name: colorise image: alexellis2/openfaas-colorization:0.4.1 environment: read_timeout: 60s url_mode: "true" write_debug: "false" write_timeout: 60s labels: com.openfaas.ui.ext: jpg
  • 30.
    Function CRD apiVersion: openfaas.com/v1alpha2 kind:Function metadata: name: generate-pdf spec: name: generate-pdf image: alexellis2/generate-pdf:latest environment: write_timeout: "10s" # Create a new Function $ faas-cli new --lang go generate-pdf
 $ faas-cli generate -f generate-pdf.yml # Or from Function Store $ faas-cli generate --from-store colorise
  • 31.
    GitOps to deployfunctions apiVersion: helm.fluxcd.io/v1 kind: HelmRelease metadata: name: functions namespace: openfaas-fn annotations: fluxcd.io/ignore: "false" fluxcd.io/automated: "false" filter.fluxcd.io/certinfo: semver:~1.0 filter.fluxcd.io/podinfo: semver:~3.1 spec: releaseName: functions chart: git: git@github.com:alexellis/openfaas-flux ref: master path: functions values: certinfo: image: stefanprodan/certinfo:1.0.0 podinfo: image: stefanprodan/podinfo:3.1.0
  • 32.
    Function CRD apiVersion: openfaas.com/v1alpha2 kind:Function metadata: name: podinfo labels: {{ include "functions.labels" . | indent 4 }} spec: name: podinfo image: {{ .Values.podinfo.image }} readOnlyRootFilesystem: true annotations: com.openfaas.health.http.initialDelay: 2s com.openfaas.health.http.path: /healthz labels: com.openfaas.scale.min: "1" com.openfaas.scale.max: "5" environment: PODINFO_PORT: "8080" PODINFO_UI_COLOR: “#34577c"
  • 33.
  • 34.
    GitOps conclusion ⚖ •FluxCD • Pull-based (polling) • Repo for config/code • Flux per repo • Limited GitHub/ GitLab integration (no statuses) • No ARM support • Alternative • Push-based (webhooks) • Harder to recover • 1 repo for config/code • Tools can be shared • Statuses and checks • ARM support
  • 35.
    In summary 💻 •Serverless 2.0 (w/Kubernetes) • anything, anywhere, any scale • Template Store • reduce duplication, maintenance
 • OpenFaaS Cloud (push) • Serverless PaaS with GitOps • FluxCD & HelmOperator (pull) • CD for OpenFaaS & Functions with CRD
  • 36.
    Connect & Learn👋 • Docs & workshop • Blog posts & tutorials • Join the community on Slack https://openfaas.com/
  • 37.