Serverless中译为“无服务器”,可以称为无服务器计算。可能有人要问了:“没有服务器,那还怎么部署应用程序?”然而,Serverless这个概念并不代表真正的不需要服务器,只是开发人员不再需要购买、管理或维护服务器,因此可以理解为应用开发者无需管理服务器。
Serverless架构的核心思想,就是将提供服务资源的基础设施抽象成各种服务,以API接口的方式供给用户按需调用,真正做到按需伸缩、按使用收费。和传统方式相比,采用Serverless架构的应用资源利用率更高,能更好地利用闲置服务器。
Faas(function as a service),函数即服务,就是用户只需要编写一个函数功能即可提供服务,不需要额外去关心开发配置和部署。
openfaas是其中的一种实现方式。https://github.com/openfaas/faas
openfaas的安装部署操作如下:
(1)安装cli
curl -sL https://cli.openfaas.com | sh
(2)创建namespace
kubectl apply -f namespaces.ym
PASSWORD=admin123
[root@wcz faas-netes-master]# echo $PASSWORD > passwd
[root@wcz faas-netes-master]# kubectl -n openfaas create secret generic basic-auth \
--from-literal=basic-auth-user=admin \ --from-literal=basic-auth-password="$PASSWORD"
(3)部署
kubectl apply -f ./yaml
查看状态
kubectl get pods -n openfaas --watch
NAME READY STATUS RESTARTS AGE
alertmanager-585697d4cc-6l569 0/1 ContainerCreating 0 39s
basic-auth-plugin-bc899c574-m9tcl 0/1 Running 0 39s
gateway-8974567f-gmn9z 0/2 ContainerCreating 0 39s
nats-7d86c64647-rxj57 0/1 ContainerCreating 0 38s
prometheus-568499cbd8-scjc4 0/1 ContainerCreating 0 37s
queue-worker-77f4446d48-f7w4w 0/1 ContainerCreating 0 38s
查看service
kubectl get service -n openfaas
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager ClusterIP 10.111.105.55 <none> 9093/TCP 30m
basic-auth-plugin ClusterIP 10.104.65.167 <none> 8080/TCP 30m
gateway ClusterIP 10.109.121.39 <none> 8080/TCP 30m
gateway-external NodePort 10.102.78.153 <none> 8080:31112/TCP 30m
nats ClusterIP 10.108.62.11 <none> 4222/TCP 30m
prometheus ClusterIP 10.105.114.112 <none> 9090/TCP 30m
(4)登录
Set OPENFAAS_URL:
export OPENFAAS_URL=http://127.0.0.1:31112
If not using a NodePort, or if using KinD:
kubectl port-forward svc/gateway -n openfaas 31112:8080 &
访问:http://ip:31112/ui/
遇到的问题及解决方法:
(1)gateway组件一直无法启动
gateway-8974567f-gmn9z 1/2 CrashLoopBackOff 5 49m
gateway-8974567f-gmn9z 1/2 ErrImagePull 5 50m
gateway-8974567f-gmn9z 1/2 ErrImagePull 5 50m
gateway-8974567f-gmn9z 1/2 ImagePullBackOff 5 50m
gateway-8974567f-gmn9z 1/2 ErrImagePull 5 51m
gateway-8974567f-gmn9z 1/2 ImagePullBackOff 5 51m
gateway-8974567f-gmn9z 1/2 ErrImagePull 5 52m
gateway-8974567f-gmn9z 1/2 ImagePullBackOff 5 52m
查看yaml/gateway-dep.yml,找到其中的部分代码
image: ghcr.io/openfaas/faas-netes:0.13.1
imagePullPolicy: Always
手动pull镜像
docker pull ghcr.io/openfaas/gateway:0.20.11
修改 imagePullPolicy,
imagePullPolicy: IfNotPresent
删除并重新部署
kubectl delete -f ./yaml
kubectl apply -f ./yaml
(2)开放访问端口