本文共 2932 字,大约阅读时间需要 9 分钟。
Fission 是一个类似AWS lamba的一个服务,其Github地址:
相似的同类产品有kubeless,knative,都是属于,其中可以在katacoda.com优先体验下。
相比kubeless在部署和使用上相对简单,而比较受关注的,还处于孵化阶段,目前暂没办法进行比较。用户可以运行任意语言编写的代码
可以运行任意时间 可以在任何地方运行 利用已有服务或者第三方资源 几秒内完成执行{docker pull fission/fission-bundledocker pull fission/fetcherdocker pull fission/alpinecurldocker pull fission/pre-upgrade-checksdocker pull nats-streamingdocker pull fission/fluentddocker pull tutum/influxdbdocker pull fission/node-env}
helm install --namespace fission --set serviceType=NodePort,routerServiceType=NodePort http://7j1x5e.com1.z0.glb.clouddn.com/fission-all-0.9.2.0.tgz
curl -Lo fission https://github.com/fission/fission/releases/download/0.9.2/fission-cli-linux && chmod +x fission && sudo mv fission /usr/local/bin/
fission env create --name nodejs --image fission/node-env
wget https://raw.githubusercontent.com/fission/fission/master/examples/nodejs/weather.js[root@master ~]# fission function create --name weather --env nodejs --code weather.jsfunction 'weather' created
[root@master ~]# fission route create --method POST --url /weather --function weathertrigger '222c1052-9c19-4e88-a544-a55bdaf18b99' created
[root@master ~]# curl -qs -H "Content-Type: application/json" -X POST -d '{"location":"Sieteiglesias, Spain"}' http://127.0.0.1:31314/weather|jq{ "text": "It is 17 celsius degrees in Sieteiglesias, Spain and Partly Cloudy"}
[root@master ~]# curl -qs -H "Content-Type: application/json" -X POST -d '{"location":"xiamen, China"}' http://127.0.0.1:31314/weather|jq{ "text": "It is 28 celsius degrees in xiamen, China and Mostly Cloudy"}
[root@master ~]# cat weather.js'use strict';const rp = require('request-promise-native');module.exports = async function (context) { const stringBody = JSON.stringify(context.request.body); const body = JSON.parse(stringBody); const location = body.location; if (!location) { return { status: 400, body: { text: 'You must provide a location.' } }; } try { const response = await rp(`https://query.yahooapis.com/v1/public/yql?q=select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="${location}") and u="c"&format=json`); const condition = JSON.parse(response).query.results.channel.item.condition; const text = condition.text; const temperature = condition.temp; return { status: 200, body: { text: `It is ${temperature} celsius degrees in ${location} and ${text}` }, headers: { 'Content-Type': 'application/json' } }; } catch (e) { console.error(e); return { status: 500, body: e }; }}
转载于:https://blog.51cto.com/13922668/2159680