前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用 Kubeless Serverless Plugin 部署与管理 Kubeless 函数 | 玩转 Kubeless

使用 Kubeless Serverless Plugin 部署与管理 Kubeless 函数 | 玩转 Kubeless

原创
作者头像
donghui
修改2021-01-18 17:59:02
7790
修改2021-01-18 17:59:02
举报
文章被收录于专栏:donghui的博客donghui的博客

Kubeless 是一个 Kubernetes 原生的 Serverless 解决方案。

Serverless Framework 是一个命令行工具,支持将函数部署到不同平台(如:AWS Lambda、Azure Functions、Google CloudFunctions、腾讯云云函数SCF等等)并对它进行管理。

Kubeless Serverless Plugin 使得通过 Serverless Framework 部署函数到 Kubeless 成为可能。

本文将介绍使用 Kubeless Serverless Plugin 部署与管理 Kubeless 函数。

环境说明

操作系统:macOS

Kubernetes 版本:v1.15.5

Kubeless 版本:v1.0.7

安装 serverless

serverless 可以通过 npm 命令安装:

代码语言:javascript
复制
$ npm install serverless -g

示例体验

使用 git 克隆 serverless-kubeless 仓库,并查看示例函数。

serverless.yml 中有几个关键字段:service、provider、plugins、functions,其中 provider 下面还有 name 和 runtime。

从 package.json 文件内容中可以看出依赖中包括 serverless-kubeless。

代码语言:javascript
复制
$ git clone https://github.com/serverless/serverless-kubeless
$ cd serverless-kubeless/examples/get-python
$ cat serverless.yml
service: hello


provider:
  name: kubeless
  runtime: python2.7


plugins:
  - serverless-kubeless


functions:
  hello:
    description: 'Hello function'
    handler: handler.hello
$ cat package.json
{
  "name": "hello",
  "version": "1.0.0",
  "description": "Example function for serverless kubeless",
  "dependencies": {
    "serverless-kubeless": "^0.7.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "Apache-2.0"
}

下载依赖,这里用到了淘宝源:

代码语言:javascript
复制
$ npm install --registry=https://registry.npm.taobao.org

部署函数:

代码语言:javascript
复制
$ serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Deploying function hello...
Serverless: Function hello successfully deployed

查看函数状态:

代码语言:javascript
复制
$ kubectl get function
NAME    AGE
hello   2m1s
$ kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
hello-68d57655b4-cfk6b   1/1     Running   0          2m16s

调用函数:

代码语言:javascript
复制
$ serverless invoke -f hello -l
Serverless: Calling function: hello...
--------------------------------------------------------------------
hello world

查看函数日志:

代码语言:javascript
复制
$ serverless logs -f hello
10.1.0.1 - - [09/Oct/2020:09:23:17 +0000] "GET / HTTP/1.1" 200 11 "" "" 0/10532
10.1.0.1 - - [09/Oct/2020:09:23:37 +0000] "GET /healthz HTTP/1.1" 200 2 "" "kube-probe/1.16+" 0/138
10.1.0.1 - - [09/Oct/2020:09:24:07 +0000] "GET /healthz HTTP/1.1" 200 2 "" "kube-probe/1.16+" 0/182

获取函数信息:

代码语言:javascript
复制
$ serverless info
Service Information "hello"
Cluster IP:  10.107.27.134
Type:  ClusterIP
Ports:
  Name:  http-function-port
  Protocol:  TCP
  Port:  8080
  Target Port:  8080
Function Info
Description: Hello function
Labels:
  created-by: kubeless
  function: hello
Handler:  handler.hello
Runtime:  python2.7
Dependencies:

修改函数后,重新部署:

代码语言:javascript
复制
$ serverless deploy function -f hello

这里遇到了问题,导致函数重新部署失败,详情参见:https://github.com/serverless/serverless-kubeless/issues/201

删除函数:

代码语言:javascript
复制
$ serverless remove
Serverless: Removing function: hello...

参考

https://github.com/serverless/serverless-kubeless

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 环境说明
  • 安装 serverless
  • 示例体验
  • 参考
相关产品与服务
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档