openfaas函数部署

1.部署openfaas中的实例函数

  1. git源码

    1
    Git clone https://github.com/openfaas/faas.git && cd ./faas
  2. 保存登陆凭证

    1
    echo -n admin | faas-cli login -g http://localhost:31112 -u admin --password-stdin
  3. 运行以下faas-cli命令,该命令获取堆栈清单的路径和OpenFaaS服务器的地址

    1
    faas-cli deploy -f ./faas/stack.yml --gateway https://localhost:31112

  4. 登陆ui界面查看function函数

    查询部署的function函数

    1
    curl -u admin:admin -X GET https://localhost:31112/system/functions | jq

    查看faas组件相关运行情况

    1
    kubectl get pods -n openfaas

    查看faas部署的函数pod创建情况

    1
    kubectl get pods -n openfaas-fn

2.自编译函数部署(python)

  1. 创建函数

    1
    faas-cli new --lang python hello-python

    这将为您创建三个文件:

    1
    2
    3
    hello-python/handler.py
    hello-python/requirements.txt
    hello-python.yml
  2. 编辑主函数handler.py(vi hello-python/handler.py)

    1
    2
    def handle(req):
    print("Hello! You said: " + req)
  3. 编辑编译的yml文件hello-python.yml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    provider:
    name: faas
    gateway: http://localhost:8080

    functions:
    hello-python:
    lang: python
    handler: ./hello-python
    image: localhost:5000/hello-python //镜像存储地址

    yml文件的相关配置相关介绍

    1
    2
    3
    4
    5
    6
    7
    8
    9
    gateway-在这里,我们可以根据需要指定远程网关,编程语言是什么以及处理程序在文件系统中的位置。

    functions -此块定义了我们堆栈中的函数

    lang: python-即使在后台使用Docker打包功能。除非您愿意,否则不必编写自己的Dockerfile。

    handler -这是您handler.py文件以及您需要的任何其他源代码的文件夹/路径

    image-这是Docker映像名称。如果要推送到Docker Hub,请将前缀从hello-python更改为包括您的Docker Hub帐户-即longjie/hello-python 并登陆。如果为私库更改为私库地址如:localhost:5000/hello-python
  4. 编译函数

    1
    faas-cli build -f ./hello-python.yml
  5. 推送函数镜像到注册表

    1
    faas-cli push -f ./hello-python.yml
  6. 部署函数到openfaas服务

    1
    faas-cli deploy -f ./hello-python.yml --gateway http://localhost:31112
  7. 登陆ui界面查看function函数

    1
    http://localhost:31112/ui
打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2018-2020 丁振莹
  • 访问人数: | 浏览次数:

你的每一分支持,是我努力下去的最大的力量 ٩(๑❛ᴗ❛๑)۶

支付宝
微信