layout: post
categories: serverless kubernetes ingress kubeless
title: serverless demo for kubernetes + ingress [原创]
date: 2017-12-29 00:11:45 +0800
description: 通过 Serverless 创建 functionkubeless)以及简化开。
minikube start --docker-env HTTP_PROXY=http://192.168.155.2:8118 \
--docker-env HTTPS_PROXY=https://192.168.155.2:8118
创建一个空的目录一会要用到
安装 serverless npm install serverless
安装 serverless-kubeless npm install serverless-kubeless
创建一个serverless function serverless create --template kubeless-python
看看serverless 支持多少模版
执行创建命令
serverless create --template kubeless-python
➜ demo2 serverless create --template kubeless-python
Serverless: Generating boilerplate...
_______ __
| _ .-----.----.--.--.-----.----| .-----.-----.-----.
| |___| -__| _| | | -__| _| | -__|__ --|__ --|
|____ |_____|__| \___/|_____|__| |__|_____|_____|_____|
| | | The Serverless Application Framework
| | serverless.com, v1.25.0
-------'
Serverless: Successfully generated boilerplate for template: "kubeless-python"
Serverless: NOTE: Please update the "service" property in serverless.yml with your service name
里面会出现四个文件 ,第一个git的忽略文件(不用git可能没有)
第二个 是function 的主体
第三个是serverless 部署依赖的yml
import json
def hello(request):
body = {
"message": "Go Serverless v1.0! Your function executed successfully!",
"input": request.json
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response
# Welcome to Serverless!
#
# For full config options, check the kubeless plugin docs:
# https://github.com/serverless/serverless-kubeless
#
# For documentation on kubeless itself:
# http://kubeless.io
# Update the service name below with your own service name
service: hello-world
# Please ensure the serverless-kubeless provider plugin is installed globally.
# $ npm install -g serverless-kubeless
#
# ...before installing project dependencies to register this provider.
# $ npm install
provider:
name: kubeless
runtime: python2.7
plugins:
- serverless-kubeless
functions:
demo2: # 有重名 hello 所以改成demo2
handler: handler.hello
package.json [可以不用管]
以上的Serverless 可以运行了
开始部署
提示 serverless
可以简写 sls
➜ demo2 serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Deploying function demo2...
Serverless: Function demo2 successfully deployed
Ingress
kubeless ingress create ingress-demo2 -n default --function demo2
# 参数介绍
# ingress-demo 是ingress 的名字
# -n 是kubernetes 的命名空间
# --function 是你要绑定到那个 function
kubeless ingress list
demo2.192.168.64.2.nip.io
测试通过
npm install serverless-kubeless
aws lambda
还有 fnproject
转载请注明出处,本文采用 CC4.0 协议授权