DEPLOYING GO FUNCTIONS

Julien Bisconti

SRE / Data Engineer

Google Cloud Platform icon

contact

g.dev/julien

slides: bisconti.cloud

Demo

openfaas logo


git clone https://github.com/openfaas/faas-netes
cd faas-netes
make start_kind

templates


import (
    "fmt"
    "io/ioutil"
    "log"
    "os"
    "handler/function"
)
func main() {
    input, err := ioutil.ReadAll(os.Stdin)
    if err != nil {
        log.Fatalf("Unable to read standard input: %s", err.Error())
    }
    fmt.Println(function.Handle(input))
}

See all templates

functions


// Handle a serverless request
func Handle(req []byte) string {
  return fmt.Sprintf("Hello, Go. You said: %s", string(req))
}

face detection handler

dockerfile

# Populate example here - i.e. "cat", "sha512sum" or "node index.js"
ENV fprocess="./handler"
# Set to true to see request in function logs
ENV write_debug="false"
EXPOSE 8080
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1
CMD [ "fwatchdog" ]

How does it work

  • OpenFaas API Gateway routes into functions
  • Runs inside a container
  • Uses a watchdog process (web server)
  • Process STDIN and returns to STDOUT
  • Collects metrics in Prometheus

Why deploying Go functions ?

Simplicity is complicated

Rob Pike

The Art of UNIX programming

dotGo 2015 - Rob Pike - Simplicity is Complicated

production grade infrastructure

Yevgeniy Brikman - Lessons from 300k+ Lines of Infrastructure Code

why does it take so long

Yak Shaving

Yak Shaving

" we should build our own X "

where "X" is anything not related to the business

Example: framework, in-memory database, queue system, new programming language, etc.

We could build it

BUT

spending time on the business

makes more sense financially

build OR buy

Tweet about datacenter

whole thread

build OR buy

Restaurants buy, cook and sell food.

Very few do farming and even less are good at both.

Why deploying Go functions ?

Mental limitations


  • # decisions / day
  • # things to remember
  • speed of memory / reflexes

Consistency is key

source

Archives of the History of American Psychology, The Center for the
History of Psychology, The University of Akron

army report uniformity

Why deploying Go functions ?

no code repository

Mindset

connect services

Patrick Debois - From serverless to Service Full

Name a service for :

  • mails
  • chat
  • pictures
  • files
  • code
  • dns
  • payment

tradeoffs

Developer time (build)
Use a product (buy)

On premise: fixed price and capacity
Cloud: pay for what you use

latency versus throughput

cold start ?

👉 strategy

mapping

Simon Wardly - Mapping

Why deploying Go functions ?

Pipelines are software too

How to change the system

pipeline code > function code

⬅️ SHIFT LEFT

delivery diagram

How to test and deploy new pipelines ?

" X-as-Code "

where "X" can be:

infra

config

build

policy

deployment

pipeline

resiliency

" X-as-Code "

where "X" can be:

infra

config

build

policy

deployment

pipeline

resiliency

👉

👉

👉

👉

👉

👉

👉

Terraform

YAML ( or CUE ?)

Dockerfile

Open Policy Agent

YAML (Kubernetes)

Jenkins ( or Tekton / Prow ?)

ChaosToolkit

Why deploying Go functions ?

Focus on code

OR?

Focus on:

  • code
  • business features
  • security
  • monitoring
  • performance
  • productivity
  • SLI/SLO/SLA
  • cost/resource optimization

Why deploying Go functions ?

In the ☁️


docker pull esimov/pigo-openfaas:0.1
gcloud auth configure-docker
export IMAGE="eu.gcr.io/${PROJECT_ID}/pigo-openfaas"
docker tag esimov/pigo-openfaas:0.1 "${IMAGE}"
docker push "${IMAGE}"
gcloud beta run deploy pigo-openfaas --platform=managed --region=us-central1 --image="${IMAGE}" --allow-unauthenticated --set-env-vars=output_mode=image --set-env-vars=input_mode=url 
export FUNCTION_URL="..."
export IMG_URL="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cc/NASA_Astronaut_Group_18.jpg/1200px-NASA_Astronaut_Group_18.jpg"
curl -H 'Content-Type: binary/octet-stream' --data-binary "${IMG_URL}" "${FUNCTION_URL}" > target.jpg

Resources

free stuff

tinyurl.com/FreeK8SQuest

THANK YOU

and I'm sorry 🙏
If you had to maintain my code
I hope you learned more by maintaining it
than me by writing it

contact

https://bisconti.cloud/

@julienBisconti

Slides made with Reveal.js and hugo-reveal