IT Panda Blog

Life is fantastic


  • Home

  • Tags

  • Categories

  • Archives

OpenFaaS 101 - 2 : 安装 OpenFaaS 以及第一个 Function

Posted on 2020-05-03 Edited on 2020-05-04 In serverless , faas , openfaas

首先 OpenFaaS 可以部署在 k8s, OpenShift, Docker Swarm 上,其中官方推荐使用 k8s

Install faas-cli

如果是Mac的话,可以直接 brew install faas-cli

Create two namespaces openfaas & openfaas-fn

kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml

安装

本地dev安装

  • create secret: kubectl -n openfaas create secret generic basic-auth --from-literal=basic-auth-user=admin --from-literal=basic-auth-password=admin
  • clone the project: git clone https://github.com/openfaas/faas-netes
  • install: cd faas-netes, kubectl apply -f ./yaml 会安装一系列pod/service/configmap…
  • setup credential: export OPENFAAS_URL=http://<your-ip>:31112, echo -n 'admin' | faas-cli login --password-stdin 第一步设置的secret
  • visit: http://<your-ip>:31112

Production安装推荐使用 Helm

添加helm repo
helm repo add openfaas https://openfaas.github.io/faas-netes/

1
2
3
4
5
6
7
helm repo update \
&& helm upgrade openfaas --install openfaas/openfaas \
--namespace openfaas \
--set functionNamespace=openfaas-fn \
--set async=true \
--set openfaasImagePullPolicy=IfNotPresent \ #这个很重要,使用上面kubectl方式安装的时候,很难指定pullpolicy
--set faasnetes.imagePullPolicy=IfNotPresent

具体的configuration,可以看这里

尝试 Deploy Function

完成上述安装步骤之后,就可以尝试部署Function了;deploy function可以通过UI/Restful API/CLI多种方式实现,其实都是内部调用api..

首先看下UI方式,点击Deploy New Function

选择一个感兴趣的尝试,当然我选择,输入字符,输出ASCII logo的func

点击右下角Deploy之后,可以直观的看到,这里OpenFaaS的策略是,部署image为pod,等待状态变为Ready即可; 输入字符,点击invoke就可以得到结果

上述方法是在UI上直接操作,太黑盒了;可以使用faas-cli来创建;先删除这个Function

1
2
3
4
5
# 下面的命令效果跟UI操作一样
faas-cli store list
faas-cli store deploy figlet
faas-cli list
echo "REX COOL" | faas-cli invoke figlet

下一篇,尝试创建一个自己的Function

serverless faas service mesh openfaas cloud computing
OpenFaaS 101 - 1 : Serverless & Faas
OpenFaaS 101 - 3:Hello World
  • Table of Contents
  • Overview
Rex

Rex

25 posts
26 categories
49 tags
Links
  • GitHub
  1. 1. Install faas-cli
  2. 2. Create two namespaces openfaas & openfaas-fn
  3. 3. 安装
    1. 3.1. 本地dev安装
    2. 3.2. Production安装推荐使用 Helm
  4. 4. 尝试 Deploy Function
© 2019 – 2020 作者拥有版权,转载请注明出处