溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何使用Kubeless Serverless Plugin部署與管理Kubeless 函數(shù)

發(fā)布時間:2021-12-16 16:25:41 來源:億速云 閱讀:131 作者:柒染 欄目:云計算

如何使用Kubeless Serverless Plugin部署與管理Kubeless 函數(shù),相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

Kubeless 是一個 Kubernetes 原生的 Serverless 解決方案。

Serverless Framework 是一個命令行工具,支持將函數(shù)部署到不同平臺(如:AWS Lambda、Azure Functions、Google CloudFunctions、騰訊云云函數(shù)SCF等等)并對它進行管理。

Kubeless Serverless Plugin 使得通過 Serverless Framework 部署函數(shù)到 Kubeless 成為可能。

下面將介紹使用 Kubeless Serverless Plugin 部署與管理 Kubeless 函數(shù)。

環(huán)境說明

操作系統(tǒng):macOS

Kubernetes 版本:v1.15.5

Kubeless 版本:v1.0.7

安裝 serverless

serverless 可以通過 npm 命令安裝:

$ npm install serverless -g

示例體驗

使用 git 克隆 serverless-kubeless 倉庫,并查看示例函數(shù)。

serverless.yml 中有幾個關(guān)鍵字段:service、provider、plugins、functions,其中 provider 下面還有 name 和 runtime。

從 package.json 文件內(nèi)容中可以看出依賴中包括 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

部署函數(shù):

$ serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Deploying function hello...
Serverless: Function hello successfully deployed

查看函數(shù)狀態(tài):

$ kubectl get function
NAME    AGE
hello   2m1s
$ kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
hello-68d57655b4-cfk6b   1/1     Running   0          2m16s

調(diào)用函數(shù):

$ serverless invoke -f hello -l
Serverless: Calling function: hello...
--------------------------------------------------------------------
hello world


查看函數(shù)日志:

$ 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

獲取函數(shù)信息:

$ 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:

修改函數(shù)后,重新部署:

$ serverless deploy function -f hello

這里遇到了問題,導(dǎo)致函數(shù)重新部署失敗,詳情參見:https://github.com/serverless/serverless-kubeless/issues/201

刪除函數(shù):

$ serverless remove
Serverless: Removing function: hello...

看完上述內(nèi)容,你們掌握如何使用Kubeless Serverless Plugin部署與管理Kubeless 函數(shù)的方法了嗎?如果還想學到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI