OpenFaaS 101 - 2 : 安裝 OpenFaaS 以及第一個 Function

首先 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/

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

# 下面的命令效果跟UI操作一樣
faas-cli store list
faas-cli store deploy figlet
faas-cli list
echo "REX COOL" | faas-cli invoke figlet

下一篇,嘗試創建一個自己的Function

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章