├── .gitignore ├── LICENSE ├── README.md ├── Slides.pdf └── demo ├── .gitignore ├── Dockerfile-openfaas ├── cleanup.sh ├── demo-magic.sh ├── demo.sh ├── docker-compose.yaml ├── get-tax.yml ├── get-tax ├── handler.py └── requirements.txt ├── openfaas-bootstrap.sh ├── start-and-watch.sh └── start-demo.sh /.gitignore: -------------------------------------------------------------------------------- 1 | openfaas/results/* 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Carson A 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Knative Vs OpenFaaS (vs Lambda) 2 | 3 | ## Slides 4 | 5 | The slides are found here in PDF version. A live version is shared on [google docs](https://docs.google.com/presentation/d/1ExXpbMiS79PXYvOp86iyPVrE8V3HVKc84I1kXHZwrSM/edit?usp=sharing) 6 | 7 | ## Demo 8 | 9 | The demo is self-contained and minimal. The only requirements to run the demo are [Docker](https://www.docker.com/) and [docker-compose](https://docs.docker.com/compose/). 10 | 11 | ### Run the Demo 12 | 13 | * `cd demo` 14 | * `./start-and-watch.sh` 15 | * `./start-demo.sh` 16 | * Optional. Use `./cleanup.sh` to fully clean up and delete the demo cluster 17 | 18 | ### Tools 19 | 20 | * [Docker](https://www.docker.com/) 21 | * [docker-compose](https://docs.docker.com/compose/) 22 | * [k3s](https://github.com/rancher/k3s) 23 | * [demo-magic](https://github.com/paxtonhare/demo-magic) 24 | * [vegeta](https://github.com/tsenart/vegeta) 25 | 26 | -------------------------------------------------------------------------------- /Slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carsonoid/talk-knative-vs-openfaas/90d495675634865f88eeac59257726792dc83d6b/Slides.pdf -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | template 2 | kubeconfig.yaml 3 | preload-images/*.tar 4 | build 5 | -------------------------------------------------------------------------------- /demo/Dockerfile-openfaas: -------------------------------------------------------------------------------- 1 | FROM alpine:3.9 2 | 3 | RUN apk update && apk add curl bash pv 4 | 5 | RUN curl -L -o - https://storage.googleapis.com/kubernetes-helm/helm-v2.13.1-linux-amd64.tar.gz | tar -zxvf - linux-amd64/helm && \ 6 | mv linux-amd64/helm /usr/local/bin/helm && \ 7 | rm -rf linux-amd64 && \ 8 | chmod +x /usr/local/bin/helm 9 | 10 | RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \ 11 | mv kubectl /usr/local/bin/kubectl && \ 12 | chmod +x /usr/local/bin/kubectl 13 | 14 | RUN curl -LO https://github.com/openfaas/faas-cli/releases/download/0.8.6/faas-cli && \ 15 | mv faas-cli /usr/local/bin/faas-cli && \ 16 | chmod +x /usr/local/bin/faas-cli 17 | 18 | RUN curl -L -o - https://github.com/tsenart/vegeta/releases/download/cli%2Fv12.2.1/vegeta-12.2.1-linux-amd64.tar.gz | tar -zxvf - vegeta && \ 19 | mv vegeta /usr/local/bin/vegeta && \ 20 | chmod +x /usr/local/bin/vegeta 21 | -------------------------------------------------------------------------------- /demo/cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker-compose kill 4 | 5 | # Delete containers and volumess 6 | docker-compose down -v 7 | -------------------------------------------------------------------------------- /demo/demo-magic.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################### 4 | # 5 | # demo-magic.sh 6 | # 7 | # Copyright (c) 2015 Paxton Hare 8 | # 9 | # This script lets you script demos in bash. It runs through your demo script when you press 10 | # ENTER. It simulates typing and runs commands. 11 | # 12 | ############################################################################### 13 | 14 | # the speed to "type" the text 15 | TYPE_SPEED=20 16 | 17 | # no wait after "p" or "pe" 18 | NO_WAIT=false 19 | 20 | # if > 0, will pause for this amount of seconds before automatically proceeding with any p or pe 21 | PROMPT_TIMEOUT=0 22 | 23 | # don't show command number unless user specifies it 24 | SHOW_CMD_NUMS=false 25 | 26 | 27 | # handy color vars for pretty prompts 28 | BLACK="\033[0;30m" 29 | BLUE="\033[0;34m" 30 | GREEN="\033[0;32m" 31 | GREY="\033[0;90m" 32 | CYAN="\033[0;36m" 33 | RED="\033[0;31m" 34 | PURPLE="\033[0;35m" 35 | BROWN="\033[0;33m" 36 | WHITE="\033[1;37m" 37 | COLOR_RESET="\033[0m" 38 | 39 | C_NUM=0 40 | 41 | # prompt and command color which can be overriden 42 | DEMO_PROMPT="$ " 43 | DEMO_CMD_COLOR=$WHITE 44 | DEMO_COMMENT_COLOR=$GREY 45 | 46 | ## 47 | # prints the script usage 48 | ## 49 | function usage() { 50 | echo -e "" 51 | echo -e "Usage: $0 [options]" 52 | echo -e "" 53 | echo -e "\tWhere options is one or more of:" 54 | echo -e "\t-h\tPrints Help text" 55 | echo -e "\t-d\tDebug mode. Disables simulated typing" 56 | echo -e "\t-n\tNo wait" 57 | echo -e "\t-w\tWaits max the given amount of seconds before proceeding with demo (e.g. '-w5')" 58 | echo -e "" 59 | } 60 | 61 | ## 62 | # wait for user to press ENTER 63 | # if $PROMPT_TIMEOUT > 0 this will be used as the max time for proceeding automatically 64 | ## 65 | function wait() { 66 | if [[ "$PROMPT_TIMEOUT" == "0" ]]; then 67 | read -rs 68 | else 69 | read -rst "$PROMPT_TIMEOUT" 70 | fi 71 | } 72 | 73 | ## 74 | # print command only. Useful for when you want to pretend to run a command 75 | # 76 | # takes 1 param - the string command to print 77 | # 78 | # usage: p "ls -l" 79 | # 80 | ## 81 | function p() { 82 | if [[ ${1:0:1} == "#" ]]; then 83 | cmd=$DEMO_COMMENT_COLOR$1$COLOR_RESET 84 | else 85 | cmd=$DEMO_CMD_COLOR$1$COLOR_RESET 86 | fi 87 | 88 | # render the prompt 89 | x=$(PS1="$DEMO_PROMPT" "$BASH" --norc -i &1 | sed -n '${s/^\(.*\)exit$/\1/p;}') 90 | 91 | # show command number is selected 92 | if $SHOW_CMD_NUMS; then 93 | printf "[$((++C_NUM))] $x" 94 | else 95 | printf "$x" 96 | fi 97 | 98 | # wait for the user to press a key before typing the command 99 | if !($NO_WAIT); then 100 | wait 101 | fi 102 | 103 | if [[ -z $TYPE_SPEED ]]; then 104 | echo -en "$cmd" 105 | else 106 | echo -en "$cmd" | pv -qL $[$TYPE_SPEED+(-2 + RANDOM%5)]; 107 | fi 108 | 109 | # wait for the user to press a key before moving on 110 | if !($NO_WAIT); then 111 | wait 112 | fi 113 | echo "" 114 | } 115 | 116 | ## 117 | # Prints and executes a command 118 | # 119 | # takes 1 parameter - the string command to run 120 | # 121 | # usage: pe "ls -l" 122 | # 123 | ## 124 | function pe() { 125 | # print the command 126 | p "$@" 127 | 128 | # execute the command 129 | eval "$@" 130 | } 131 | 132 | ## 133 | # Enters script into interactive mode 134 | # 135 | # and allows newly typed commands to be executed within the script 136 | # 137 | # usage : cmd 138 | # 139 | ## 140 | function cmd() { 141 | # render the prompt 142 | x=$(PS1="$DEMO_PROMPT" "$BASH" --norc -i &1 | sed -n '${s/^\(.*\)exit$/\1/p;}') 143 | printf "$x\033[0m" 144 | read command 145 | eval "${command}" 146 | } 147 | 148 | 149 | function check_pv() { 150 | command -v pv >/dev/null 2>&1 || { 151 | 152 | echo "" 153 | echo -e "${RED}##############################################################" 154 | echo "# HOLD IT!! I require pv but it's not installed. Aborting." >&2; 155 | echo -e "${RED}##############################################################" 156 | echo "" 157 | echo -e "${COLOR_RESET}Installing pv:" 158 | echo "" 159 | echo -e "${BLUE}Mac:${COLOR_RESET} $ brew install pv" 160 | echo "" 161 | echo -e "${BLUE}Other:${COLOR_RESET} http://www.ivarch.com/programs/pv.shtml" 162 | echo -e "${COLOR_RESET}" 163 | exit 1; 164 | } 165 | } 166 | 167 | check_pv 168 | # 169 | # handle some default params 170 | # -h for help 171 | # -d for disabling simulated typing 172 | # 173 | while getopts ":dhncw:" opt; do 174 | case $opt in 175 | h) 176 | usage 177 | exit 1 178 | ;; 179 | d) 180 | unset TYPE_SPEED 181 | ;; 182 | n) 183 | NO_WAIT=true 184 | ;; 185 | c) 186 | SHOW_CMD_NUMS=true 187 | ;; 188 | w) 189 | PROMPT_TIMEOUT=$OPTARG 190 | ;; 191 | esac 192 | done 193 | -------------------------------------------------------------------------------- /demo/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ./demo-magic.sh -n 4 | 5 | export TYPE_SPEED=60 6 | export DEMO_COMMENT_COLOR=$CYAN 7 | 8 | p "# wait for faas gateway to be ready" 9 | pe "kubectl -n openfaas rollout status -w deployment/gateway" 10 | wait 11 | 12 | # determine the generated nodeport for the gateway-ext service 13 | GATEWAY_NODEPORT=$(kubectl -n openfaas get svc gateway-external -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}') 14 | NODE_IP=$(kubectl get nodes --selector=kubernetes.io/role!=master -o jsonpath={.items[*].status.addresses[?\(@.type==\"InternalIP\"\)].address} |head -n 1) 15 | 16 | p "# Install our test function" 17 | pe "faas-cli --gateway=$NODE_IP:$GATEWAY_NODEPORT deploy -f get-tax.yml" 18 | wait 19 | 20 | p "# Invoke the test function with faas-cli" 21 | pe "echo '{\"subtotal\":100}' | faas-cli --gateway=$NODE_IP:$GATEWAY_NODEPORT invoke get-tax" 22 | wait 23 | 24 | # p "# overload the function with vegeta" 25 | pe "echo \"GET http://$NODE_IP:$GATEWAY_NODEPORT/function/get-tax\" | vegeta attack -body <( echo '{\"subtotal\":100}') | vegeta report --type hist[0,100ms,200ms,300ms,400ms,500ms,600ms,1s]" 26 | 27 | # ----------------------------- Proxy 28 | p "# Proxy connection into the faas gateway release 1 pod, Control-C to kill and continue" 29 | p "# Access the forwarded service via http://127.0.0.1:9999" 30 | pe "kubectl -n openfaas port-forward svc/gateway 9999:8080" 31 | 32 | p "# Demo done! Feel free to use continue to use kubectl or faas-cli. Or run ./cleanup.sh to delete everything" 33 | -------------------------------------------------------------------------------- /demo/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | server: 4 | image: rancher/k3s:v0.2.0 5 | command: server --disable-agent 6 | environment: 7 | - K3S_CLUSTER_SECRET=eK7rlyG9ZfjlDH4t5 8 | - K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml 9 | - K3S_KUBECONFIG_MODE=666 10 | volumes: 11 | - k8s:/var/lib/rancher/k3s 12 | - .:/output 13 | ports: 14 | - 6443:6443 15 | 16 | node: 17 | image: rancher/k3s:v0.2.0 18 | tmpfs: 19 | - /run 20 | - /var/run 21 | privileged: true 22 | volumes: 23 | - ./preload-images:/var/lib/rancher/k3s/agent/images/ 24 | depends_on: 25 | - server 26 | environment: 27 | - K3S_URL=https://server:6443 28 | - K3S_CLUSTER_SECRET=eK7rlyG9ZfjlDH4t5 29 | 30 | openfaas: 31 | build: 32 | context: . 33 | dockerfile: Dockerfile-openfaas 34 | network_mode: host 35 | depends_on: 36 | - server 37 | volumes: 38 | - .:/openfaas 39 | - ./kubeconfig.yaml:/root/.kube/config:ro 40 | working_dir: /openfaas 41 | entrypoint: 42 | - bash 43 | - ./openfaas-bootstrap.sh 44 | 45 | volumes: 46 | k8s: {} 47 | -------------------------------------------------------------------------------- /demo/get-tax.yml: -------------------------------------------------------------------------------- 1 | provider: 2 | name: openfaas 3 | gateway: http://127.0.0.1:8080 4 | functions: 5 | get-tax: 6 | lang: python 7 | handler: ./get-tax 8 | image: carsonoid/get-tax:openfaas 9 | -------------------------------------------------------------------------------- /demo/get-tax/handler.py: -------------------------------------------------------------------------------- 1 | import sys, json 2 | 3 | # EXPECTS {"subtotal":INT} 4 | def handle(req): 5 | subtotal = json.loads(req)["subtotal"] 6 | 7 | tax = subtotal * 0.047 8 | 9 | print({ "tax": tax }) 10 | -------------------------------------------------------------------------------- /demo/get-tax/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carsonoid/talk-knative-vs-openfaas/90d495675634865f88eeac59257726792dc83d6b/demo/get-tax/requirements.txt -------------------------------------------------------------------------------- /demo/openfaas-bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Get pv for demo 4 | apk update && apk add pv 5 | 6 | # Wait for cluster to be ready 7 | until kubectl get nodes &> /dev/null; do sleep 1; done 8 | 9 | # make sure helm has cluster admin permissions 10 | kubectl create clusterrolebinding helmadmin --clusterrole=cluster-admin --serviceaccount=kube-system:default 11 | 12 | # Init tiller 13 | helm init 14 | 15 | # wait for tiller to be ready 16 | kubectl rollout status -w deployment/tiller-deploy --namespace=kube-system 17 | 18 | # create OpenFaaS namespaces 19 | kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml 20 | 21 | # add OpenFaaS Helm repo 22 | helm repo add openfaas https://openfaas.github.io/faas-netes/ 23 | 24 | # get latest chart version and install 25 | helm repo update && helm upgrade --version 4.3.0 openfaas --install openfaas/openfaas \ 26 | --namespace openfaas \ 27 | --set functionNamespace=openfaas-fn \ 28 | --set operator.create=true \ 29 | --set faasnetes.imagePullPolicy=IfNotPresent \ 30 | --set ingress.enabled=true \ 31 | --set basic_auth=false \ 32 | --set basicAuthPlugin.replicas=0 33 | 34 | # Keep the container up, but die quickly 35 | while :; do sleep 3; done 36 | -------------------------------------------------------------------------------- /demo/start-and-watch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # build and export the test fn image so it doesn't have to be uploaded to a registry 4 | mkdir preload-images 5 | faas-cli build -f get-tax.yml ; docker save -o preload-images/get-tax.tar carsonoid/get-tax:openfaas 6 | 7 | # Make sure kubeconfig.yaml exists as a file 8 | touch kubeconfig.yaml 9 | 10 | # Bring up the server, recreate anon volumes 11 | docker-compose up -d -V 12 | 13 | export KUBECTL="kubectl --kubeconfig=kubeconfig.yaml " 14 | 15 | # watch the create resources 16 | watch -c bash -c : ' 17 | for ns in openfaas openfaas-fn; do 18 | echo "#=================== $ns" 19 | for obj in deployments pods; do 20 | echo "################ $obj" 21 | $KUBECTL -n $ns get $obj 22 | echo 23 | done 24 | done 25 | ' 26 | -------------------------------------------------------------------------------- /demo/start-demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker-compose exec openfaas ./demo.sh 4 | --------------------------------------------------------------------------------