Title: serverless demo for kubernetes + ingress [原创]

Categories: serverless kubernetes ingress kubeless

Description: 通过 Serverless 创建 functionkubeless)以及简化开。

Keywords: serverless

文章介绍,Serverless + kubernetes + ingress + kubeless 快速开发function 简化开发,无服务器接口,让开发更快 更爽

工具

启动Minikube

minikube start --docker-env HTTP_PROXY=http://192.168.155.2:8118 \
                 --docker-env HTTPS_PROXY=https://192.168.155.2:8118

正题

    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
    ➜  demo2 serverless deploy
    Serverless: Packaging service...
    Serverless: Excluding development dependencies...
    Serverless: Deploying function demo2...
    Serverless: Function demo2 successfully deployed

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

测试通过

总结

转载请注明出处,本文采用 CC4.0 协议授权