add faas
parent
df9ee4f8b1
commit
4505285ca8
|
@ -148,6 +148,8 @@
|
||||||
- [运行支持kubernetes原生调度的Spark程序](usecases/running-spark-with-kubernetes-native-scheduler.md)
|
- [运行支持kubernetes原生调度的Spark程序](usecases/running-spark-with-kubernetes-native-scheduler.md)
|
||||||
- [Serverless架构](usecases/serverless.md)
|
- [Serverless架构](usecases/serverless.md)
|
||||||
- [理解Serverless](usecases/understanding-serverless.md)
|
- [理解Serverless](usecases/understanding-serverless.md)
|
||||||
|
- [FaaS-函数即服务](usecases/faas.md)
|
||||||
|
- [OpenFaaS](usecases/openfaas.md)
|
||||||
- [边缘计算](usecases/edge-computing.md)
|
- [边缘计算](usecases/edge-computing.md)
|
||||||
|
|
||||||
### 开发指南
|
### 开发指南
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
Binary file not shown.
After Width: | Height: | Size: 350 KiB |
Binary file not shown.
After Width: | Height: | Size: 377 KiB |
Binary file not shown.
After Width: | Height: | Size: 291 KiB |
Binary file not shown.
After Width: | Height: | Size: 170 KiB |
|
@ -0,0 +1,86 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: faas-netesd
|
||||||
|
labels:
|
||||||
|
app: faas-netesd
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
ports:
|
||||||
|
- port: 8080
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 8080
|
||||||
|
nodePort: 31111
|
||||||
|
selector:
|
||||||
|
app: faas-netesd
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: faas-controller
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: faas-netesd
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: faas-netesd
|
||||||
|
spec:
|
||||||
|
serviceAccountName: faas-controller
|
||||||
|
containers:
|
||||||
|
- name: faas-netesd
|
||||||
|
image: sz-pg-oam-docker-hub-001.tendcloud.com/library/faas-netesd:0.3.4
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
protocol: TCP
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: 20Mi
|
||||||
|
limits:
|
||||||
|
memory: 30Mi
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: gateway
|
||||||
|
labels:
|
||||||
|
app: gateway
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
ports:
|
||||||
|
- port: 8080
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 8080
|
||||||
|
nodePort: 31112
|
||||||
|
selector:
|
||||||
|
app: gateway
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: gateway
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: gateway
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: gateway
|
||||||
|
image: sz-pg-oam-docker-hub-001.tendcloud.com/library/gateway:0.6.14
|
||||||
|
env:
|
||||||
|
- name: functions_provider_url
|
||||||
|
value: "http://faas-netesd.default.svc.cluster.local:8080/"
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
protocol: TCP
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: 20Mi
|
||||||
|
limits:
|
||||||
|
memory: 30Mi
|
|
@ -0,0 +1,80 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
labels:
|
||||||
|
app: prometheus
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
ports:
|
||||||
|
- port: 9090
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 9090
|
||||||
|
nodePort: 31119
|
||||||
|
selector:
|
||||||
|
app: prometheus
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: prometheus
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: prometheus
|
||||||
|
image: sz-pg-oam-docker-hub-001.tendcloud.com/library/prometheus:latest-k8s
|
||||||
|
command: ["prometheus","-config.file=/etc/prometheus/prometheus.yml", "-storage.local.path=/prometheus", "-storage.local.memory-chunks=10000", "--alertmanager.url=http://alertmanager.default:9093"]
|
||||||
|
ports:
|
||||||
|
- containerPort: 9090
|
||||||
|
protocol: TCP
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: 512Mi
|
||||||
|
limits:
|
||||||
|
memory: 512Mi
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: alertmanager
|
||||||
|
labels:
|
||||||
|
app: alertmanager
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
ports:
|
||||||
|
- port: 9093
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 9093
|
||||||
|
nodePort: 31113
|
||||||
|
selector:
|
||||||
|
app: alertmanager
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: alertmanager
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: alertmanager
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: alertmanager
|
||||||
|
image: sz-pg-oam-docker-hub-001.tendcloud.com/library/alertmanager:latest-k8s
|
||||||
|
command: ["/bin/alertmanager","-config.file=/alertmanager.yml", "-storage.path=/alertmanager"]
|
||||||
|
ports:
|
||||||
|
- containerPort: 9003
|
||||||
|
protocol: TCP
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: 20Mi
|
||||||
|
limits:
|
||||||
|
memory: 30Mi
|
|
@ -0,0 +1,48 @@
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
name: faas-controller
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- services
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- update
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- secrets
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- extensions
|
||||||
|
resources:
|
||||||
|
- deployments
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- update
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: faas-controller
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: faas-controller
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: faas-controller
|
||||||
|
namespace: default
|
|
@ -0,0 +1,18 @@
|
||||||
|
# FaaS-函数即服务
|
||||||
|
|
||||||
|
FaaS(Functions as a Service)函数即服务,FaaS是无服务器计算的一种形式,当前使用最广泛的是AWS的Lambada。
|
||||||
|
|
||||||
|
现在当大家讨论Serverless的时候首先想到的就是FaaS,有点甚嚣尘上了。FaaS本质上是一种事件驱动的由消息触发的服务,FaaS供应商一般会集成各种同步和异步的事件源,通过订阅这些事件源,可以突发或者定期的触发函数运行。
|
||||||
|
|
||||||
|
当前开源的FaaS框架大部分都是基于Kuberentes来实现的,例如:
|
||||||
|
|
||||||
|
- [faas-netes](https://github.com/alexellis/faas-netes) - Enable Kubernetes as a backend for Functions as a Service (OpenFaaS) <https://github.com/alexellis/faas>
|
||||||
|
- [fn](https://github.com/fnproject/fn) - The container native, cloud agnostic serverless platform. [http://fnproject.io](http://fnproject.io/)
|
||||||
|
- [funktion](https://github.com/funktionio/funktion/) - a CLI tool for working with funktion <https://funktion.fabric8.io/>
|
||||||
|
- [fx](https://github.com/metrue/fx) - Poor man's serverless framework based on Docker, Function as a Service with painless.
|
||||||
|
- [IronFunctions](https://github.com/iron-io/functions) - IronFunctions - the serverless microservices platform. [http://iron.io](http://iron.io/)
|
||||||
|
- [kubeless](https://github.com/kubeless/kubeless) - Kubernetes Native Serverless Framework [http://kubeless.io](http://kubeless.io/)
|
||||||
|
- [OpenFaaS](https://github.com/openfaas/faas) - OpenFaaS - Serverless Functions Made Simple for Docker & Kubernetes [https://blog.alexellis.io/introducing-functions-as-a-service/](https://blog.alexellis.io/introducing-functions-as-a-service/)
|
||||||
|
- [OpenWhisk](http://openwhisk.incubator.apache.org/) - Apache OpenWhisk (Incubating) is a [serverless](http://openwhisk.incubator.apache.org/serverless), open source cloud platform that executes functions in response to events at any scale.
|
||||||
|
|
||||||
|
关于整个Cloud Native开源生态,请参考[awesome-cloud-native](https://jimmysong.io/awesome-cloud-native)。
|
|
@ -0,0 +1,56 @@
|
||||||
|
# OpenFaaS
|
||||||
|
|
||||||
|
OpenFaaS一款高人气的开源的faas框架,可以在
|
||||||
|
|
||||||
|
在Kubernetes上部署OpenFaaS十分简单,用到的镜像如下:
|
||||||
|
|
||||||
|
- functions/faas-netesd:0.3.4
|
||||||
|
- functions/gateway:0.6.14
|
||||||
|
- functions/prometheus:latest-k8s
|
||||||
|
- functions/alertmanager:latest-k8s
|
||||||
|
|
||||||
|
这些镜像都存储在DockerHub上。
|
||||||
|
|
||||||
|
OpenFaaS的架构如下图:
|
||||||
|
|
||||||
|
![OpenFaaS架构](../images/openfaas-arch.jpg)
|
||||||
|
|
||||||
|
## 部署
|
||||||
|
|
||||||
|
参考[Deployment guide for Kubernetes](https://github.com/openfaas/faas/blob/master/guide/deployment_k8s.md)部署OpenFaaS。
|
||||||
|
|
||||||
|
如果您的Kuberentes集群可以访问DockerHub那么直接使用官方提供的YAML文件即可。
|
||||||
|
|
||||||
|
YAML文件见官方仓库:https://github.com/openfaas/faas-netes
|
||||||
|
|
||||||
|
### 部署同步请求
|
||||||
|
|
||||||
|
一共用到了三个YAML文件:
|
||||||
|
|
||||||
|
- faas.yml
|
||||||
|
- monitoring.yml
|
||||||
|
- rbac.yml
|
||||||
|
|
||||||
|
OpenFaaS安装好后会启动一个Prometheus。
|
||||||
|
|
||||||
|
![OpenFaaS Prometheus](../images/openfaas-prometheus.jpg)
|
||||||
|
|
||||||
|
在这里可以看到函数的运行情况。
|
||||||
|
|
||||||
|
同时OpenFaaS还提供了Dashboard,需要我们自己向Grafana中配置Prometheus数据源后导入,JSON配置见:https://grafana.com/dashboards/3526,可以下载后直接导入到Grafana中。
|
||||||
|
|
||||||
|
![OpenFaas Grafana监控](../images/openfaas-grafana.jpg)
|
||||||
|
|
||||||
|
## OpenFaaS的使用
|
||||||
|
|
||||||
|
OpenFaaS提供了便捷的UI,在部署完成后就可以通过NodePort方式访问。
|
||||||
|
|
||||||
|
![OpenFaas Dashboard](../images/openfaas-deploy-a-function.jpg)
|
||||||
|
|
||||||
|
其中已经内置了一些函数应用可供我们试用,还可以创建自己的函数。
|
||||||
|
|
||||||
|
比如内置的`NodeInfo`应用,可以获取该应用所部署到的主机的信息,如下图:
|
||||||
|
|
||||||
|
![NodeInfo执行结果](../images/openfaas-nodeinfo.jpg)
|
||||||
|
|
||||||
|
**注意:**有一些js和css文件需要翻墙才能访问,否则页面将出现格式错误。
|
|
@ -44,7 +44,7 @@ BaaS(Backend as a Service)后端即服务,一般是一个个的API调用
|
||||||
|
|
||||||
### FaaS
|
### FaaS
|
||||||
|
|
||||||
FaaS(Functions as a Service)函数即服务,FaaS是无服务器计算的额一种形式,当前使用最广泛的是AWS的Lambada。
|
FaaS(Functions as a Service)函数即服务,FaaS是无服务器计算的一种形式,当前使用最广泛的是AWS的Lambada。
|
||||||
|
|
||||||
现在当大家讨论Serverless的时候首先想到的就是FaaS,有点甚嚣尘上了。FaaS本质上是一种事件驱动的由消息触发的服务,FaaS供应商一般会集成各种同步和异步的事件源,通过订阅这些事件源,可以突发或者定期的触发函数运行。
|
现在当大家讨论Serverless的时候首先想到的就是FaaS,有点甚嚣尘上了。FaaS本质上是一种事件驱动的由消息触发的服务,FaaS供应商一般会集成各种同步和异步的事件源,通过订阅这些事件源,可以突发或者定期的触发函数运行。
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue