如何使用Kubeless Serverless Plugin部署与管理Kubeless 函数,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
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 可以通过 npm 命令安装:
$ npm install serverless -g
使用 git 克隆 serverless-kubeless 仓库,并查看示例函数。
serverless.yml 中有几个关键字段:service、provider、plugins、functions,其中 provider 下面还有 name 和 runtime。
从 package.json 文件内容中可以看出依赖中包括 serverless-kubeless。
$ 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"
}
下载依赖,这里用到了淘宝源:
$ npm install --registry=https://registry.npm.taobao.org
部署函数:
$ serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Deploying function hello...
Serverless: Function hello successfully deployed
查看函数状态:
$ kubectl get function
NAME AGE
hello 2m1s
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-68d57655b4-cfk6b 1/1 Running 0 2m16s
调用函数:
$ serverless invoke -f hello -l
Serverless: Calling function: hello...
--------------------------------------------------------------------
hello world
查看函数日志:
$ 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
获取函数信息:
$ 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:
修改函数后,重新部署:
$ serverless deploy function -f hello
这里遇到了问题,导致函数重新部署失败,详情参见:https://github.com/serverless/serverless-kubeless/issues/201
删除函数:
$ serverless remove
Serverless: Removing function: hello...
看完上述内容,你们掌握如何使用Kubeless Serverless Plugin部署与管理Kubeless 函数的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
亿速云「云数据库 MySQL」免部署即开即用,比自行安装部署数据库高出1倍以上的性能,双节点冗余防止单节点故障,数据自动定期备份随时恢复。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/donhui/blog/4911714