如何使用KubelessServerlessPlugin部署与管理Kubeless函数

如何使用Kubeless Serverless Plugin部署与管理Kubeless 函数,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

创新互联是专业的吴兴网站建设公司,吴兴接单;提供成都网站建设、成都网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行吴兴网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

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 命令安装:

$ 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 函数的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!

新闻标题:如何使用KubelessServerlessPlugin部署与管理Kubeless函数
网页地址:https://www.cdcxhl.com/article32/ghoepc.html

成都网站建设公司_创新互联,为您提供App设计手机网站建设外贸网站建设网站收录建站公司

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设公司