OpenFaaS基础 -- 部署,调用及监控函数

Kubernetes集群部署OpenFaaS ,我们了解如何部署OpenFaaS的,继续,我们学习如何部署、调用及监控函数。

接入gateway

可以选择以下任意一种方式接入:

  1. 通过kubectl port-foward的形式暴露Gateway
kubectl port-forward svc/gateway -n openfaas 8080:8080
  1. 指定gateway的地址

先获取Gateway的地址

root@node1:/home/lab# kubectl get svc -n openfaas gateway
NAME      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
gateway   ClusterIP   10.104.65.4   <none>        8080/TCP   84s

然后指定gateway的地址

root@node1:/home/lab# export OPENFAAS_URL=10.104.65.4:8080

登录

获得登录密码并登录

root@node1:/home/lab# echo $(kubectl -n openfaas get secret basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode)
yWL5HNDH7yg2
root@node1:/home/lab# faas-cli login -u admin -p yWL5HNDH7yg2
WARNING! Using --password is insecure, consider using: cat ~/faas_pass.txt | faas-cli login -u user --password-stdin
Calling the OpenFaaS server to validate the credentials...
WARNING! You are not using an encrypted connection to the gateway, consider using HTTPS.
credentials saved for admin http://10.104.65.4:8080

可以访问faas-cli list

root@node1:/home/lab# faas-cli list
Function                        Invocations     Replicas

部署函数并调用函数

OpenFaaS提供了web ui和faas-cli命令行部署函数的方式

利用ui

来到gateway的web ui界面,直接点DEPLOY NEW FUNCTION即可
在这里插入图片描述
在这里插入图片描述
部署完后稍微等一会,等函数的Statu为Ready的时候就可以直接点INVOKE调用了:在这里插入图片描述

利用faas-cli

查看已有函数,还没有部署任何函数

root@node1:/home/lab# faas-cli list
Function                        Invocations     Replicas

使用faas-cli deploy 部署函数

root@node1:/home/lab# faas-cli store deploy nodeinfo
WARNING! You are not using an encrypted connection to the gateway, consider using HTTPS.

Deployed. 202 Accepted.
URL: http://10.104.65.4:8080/function/nodeinfo

root@node1:/home/lab# faas-cli list
Function                        Invocations     Replicas
nodeinfo                        1               1    

利用faas-cli invoke调用函数,输入任意文本,Control + D停止。

root@node1:/home/lab# faas-cli invoke nodeinfo
Reading from STDIN - hit (Control + D) to stop.
fejife
Hostname: nodeinfo-77c6756589-crvst

Arch: x64
CPUs: 2
Total mem: 1993MB
Platform: linux
Uptime: 108026.43

利用Grafana监控函数调用过程

在openfaas命名空间运行Grafana

root@node1:/home/lab# kubectl -n openfaas run \
--image=stefanprodan/faas-grafana:4.6.3 \
--port=3000 \
grafana

用NodePort暴露Grafana

root@node1:/home/lab# kubectl -n openfaas expose pod grafana \
--type=NodePort \
--name=grafana

寻找Grafana的端口和地址「第二行命令中的10.59.140.215是我k8s集群一台主机的地址,换成自己相应的集群ip地址就行」:

root@node1:/home/lab# GRAFANA_PORT=$(kubectl -n openfaas get svc grafana -o jsonpath="{.spec.ports[0].nodePort}")
root@node1:/home/lab# echo $GRAFANA_PORT
30950
root@node1:/home/lab# GRAFANA_URL=http://10.59.140.215:$GRAFANA_PORT/dashboard/db/openfaas

进行端口转发以接入Grafana

root@node1:/home/lab# kubectl port-forward pod/grafana 3000:3000 -n openfaas
Forwarding from 127.0.0.1:3000 -> 3000
Forwarding from [::1]:3000 -> 3000

输入集群ip:端口(10.59.140.215:30950)
在这里插入图片描述
点左上角Home那里,选择OpenFaaS,就能看到监控情况了:
在这里插入图片描述

其他命令

faas-cli store list 查看function store里的函数
faas-cli store deploy nodeinfo 部署store里的nodeinfo函数

参考

https://github.com/openfaas/workshop/blob/master/lab2.md
《Serverless For Everyone Else》

如果对你有用,请用微信扫码奖励我叭!

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值