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