# 系统部署
fogcloud 相关镜像:
ghcr.io/fogcloud-io/fogcloud:latest
ghcr.io/fogcloud-io/fogcloud-web:latest
ghcr.io/fogcloud-io/faas-builder:latest
ghcr.io/fogcloud-io/fogcron-scheduler:latest
foglcoud 依赖以下第三方服务:
- minio
- redis
- mongodb
- postgresql
- etcd
- rabbitmq
- emqx(或 hmq/vernemq)
推荐使用 helm 进行部署,完整部署方式请参考 helm 方式
# 1 通过 docker 部署
以下只列举 fogcloud 自身服务部署,包括:
- fogcloud(后台主服务)
- fogcloud-web(前端服务)
- fogcron-scheduler(定时器调度服务)
- faasbuilder(云函数镜像编译服务)
注:docker 部署方式不支持云函数功能,若要使用该功能请使用 k8s 部署;
# 1.1 docker run 运行
# 1.1.1 获取镜像
通过 ghcr.io 获取
docker pull ghcr.io/fogcloud-io/fogcloud:latest docker pull ghcr.io/fogcloud-io/fogcloud-web:latest docker pull ghcr.io/fogcloud-io/fogcron-scheduler:latest docker pull ghcr.io/fogcloud-io/faas-builder:latest
# 1.1.2 启动容器
- 启动 fogcloud 容器
docker run -d \ --name fogcloud \ -p 4000:4000 \ -v /etc/fogcloud/config/config.yaml:/etc/fogcloud/config.yaml \ ghcr.io/fogcloud-io/fogcloud:latest
- 启动 fogcloud-web 容器
docker run -d \ --name fogcloud-web \ -p 80:8000 \ ghcr.io/fogcloud-io/fogcloud-web:latest
- 启动 fogcron-scheduler 容器
docker run -d \ --name fogcron-scheduler \ ghcr.io/fogcloud-io/fogcron-scheduler:latest
# 1.2 使用 docker-compose 创建
- 创建 docker-compose.yaml 文件
version: "3" networks: fogcloud_net: services: fogcloud: image: ghcr.io/fogcloud-io/fogcloud:latest container_name: fogcloud restart: unless-stopped networks: - fogcloud_net ports: - 4000:4000 volumes: - /etc/fogcloud/config.example.yaml:/etc/fogcloud/config.yaml command: ["fogcloud", "-c", "/etc/fogcloud/config.yaml", "-e", "production"] fogcloud-web: image: ghcr.io/fogcloud-io/fogcloud-web:latest container_name: fogcloud-web restart: unless-stopped networks: - fogcloud_net ports: - 8000:8000 fogcron-scheduler: image: ghcr.io/fogcloud-io/fogcron-scheduler:latest container_name: fogcron-scheduler volumes: - ../../../configs/fogcron/config.yaml:/etc/fogcron/config.yaml command: [ "fogcron", "schedule", "-c", "/etc/fogcron/config.yaml", "-e", "development", ]
- 部署服务
docker-compose -f docker-compose.yaml up --build -d
- 查看服务运行状态
curl localhost:4000/api/v1/ping
# 2 通过 k8s yaml 部署
- 创建命名空间
配置文件 namespace.yaml 示例:
apiVersion: v1 kind: Namespace metadata: name: fogcloud labels: name: fogcloud
运行命令:
kubectl apply -f namespace.yaml
- 创建 configmap
使用命令行直接创建 configmap:
kubectl create --namespace=fogcloud configmap fog-config \ fog-config --from-file=config.yaml=/etc/fogcloud/config.yaml
- 创建 fogcloud.yaml 文件
配置文件 fogcloud.yaml 示例:
# fogcloud-service apiVersion: v1 kind: Service metadata: labels: srv: fogcloud name: fogcloud namespace: fogcloud spec: type: NodePort ports: - name: "http" port: 4000 targetPort: 4000 nodePort: 4000 selector: app: fogcloud status: loadBalancer: {} --- # fogcloud-deployment apiVersion: apps/v1 kind: Deployment metadata: labels: dep: fogcloud name: fogcloud namespace: fogcloud spec: replicas: 3 selector: matchLabels: app: fogcloud strategy: type: Recreate template: metadata: labels: app: fogcloud spec: containers: - args: - fogcloud - -c - /etc/fogcloud/config.example.yaml - -e - development image: ghcr.io/fogcloud-io/fogcloud:latest imagePullPolicy: Always name: fogcloud ports: - containerPort: 4000 - containerPort: 15000 resources: {} volumeMounts: - mountPath: /etc/fogcloud/config.example.yaml subPath: config.example.yaml name: fogcloud-claim - mountPath: /etc/fogcloud/active.en.json subPath: active.en.json name: fogcloud-claim - mountPath: /etc/fogcloud/active.zh.json subPath: active.zh.json name: fogcloud-claim restartPolicy: Always volumes: - name: fogcloud-claim configMap: name: fog-config items: - key: config.example.yaml path: config.example.yaml - key: active.en.json path: active.en.json - key: active.zh.json path: active.zh.json status: {} --- # fogcloud-web-service apiVersion: v1 kind: Service metadata: labels: srv: fogcloud-web name: fogcloud-web namespace: fogcloud spec: ports: - name: "http" port: 4002 targetPort: 8000 selector: app: fogcloud-web status: loadBalancer: {} --- # fogcloud-web-deployment apiVersion: apps/v1 kind: Deployment metadata: labels: dep: fogcloud-web name: fogcloud-web namespace: fogcloud spec: replicas: 1 selector: matchLabels: app: fogcloud-web strategy: type: Recreate template: metadata: labels: app: fogcloud-web spec: containers: - image: ghcr.io/fogcloud-io/fogcloud-web:latest imagePullPolicy: Always name: fogcloud-web ports: - containerPort: 80 - containerPort: 443 volumeMounts: - mountPath: /etc/nginx/conf.d name: nginx-claim volumes: - name: nginx-claim configMap: name: fog-config items: - key: default_web.conf path: default.conf status: {} --- # faasbuilder-service apiVersion: v1 kind: Service metadata: annotations: labels: srv: faasbuilder name: faasbuilder namespace: fogcloud spec: ports: - name: "api" port: 8090 targetPort: 8090 selector: app: faasbuilder status: loadBalancer: {} --- # faasbuilder-deployment apiVersion: apps/v1 kind: Deployment metadata: annotations: labels: dep: faasbuilder name: faasbuilder namespace: fogcloud spec: replicas: 1 selector: matchLabels: app: faasbuilder strategy: type: Recreate template: metadata: annotations: labels: app: faasbuilder spec: containers: - image: ghcr.io/fogcloud-io/faas-builder:latest args: - -c - /etc/faasbuilder/faasbuilder.yaml env: - name: KUBECONFIG value: /etc/faasbuilder/kubeconfig imagePullPolicy: Always name: faasbuilder securityContext: privileged: true ports: - containerPort: 8090 resources: {} volumeMounts: - mountPath: /etc/faasbuilder/faasbuilder.yaml subPath: faasbuilder.yaml name: fogcloud-claim - mountPath: /etc/faasbuilder/kubeconfig subPath: kubeconfig name: fogcloud-claim restartPolicy: Always volumes: - name: fogcloud-claim configMap: name: fog-config items: - key: faasbuilder.yaml path: faasbuilder.yaml - key: kubeconfig path: kubeconfig status: {} --- # fogcron-scheduler-deployment apiVersion: apps/v1 kind: Deployment metadata: labels: dep: fogcron-scheduler name: fogcron-scheduler namespace: namespace spec: replicas: 1 selector: matchLabels: app: fogcron-scheduler strategy: type: Recreate template: metadata: labels: app: fogcron-scheduler spec: containers: - args: - fogcron - schedule - -c - /etc/fogcron/fogcron.yaml image: ghcr.io/fogcloud-io/fogcron-scheduler:latest imagePullPolicy: Always name: fogcron-scheduler resources: {} volumeMounts: - mountPath: /etc/fogcron/fogcron.yaml subPath: fogcron.yaml name: fogcron-scheduler-claim restartPolicy: Always volumes: - name: fogcron-scheduler-claim configMap: name: fog-config items: - key: fogcron.yaml path: fogcron.yaml status: {}
运行命令:
kubectl apply -f fogcloud.yaml
# 3 通过 helm 部署
# 3.1 安装前准备
- 安装 kubernetes (opens new window) 1.19+
- 安装并设置 kubectl (opens new window) 1.19+
- 安装 helm (opens new window) 3+
- 使用 helm 安装 fission (opens new window)
# 3.2 获取 chart
helm repo add fogcloud-charts https://fogcloud-io.github.io/fogcloud-charts helm repo update helm pull fogcloud-charts/fogcloud-charts --untar
# 3.3 安装 chart
- 拷贝 fogcloud-charts 目录的 values.yaml 文件,并命名为 myvalues.yaml
- 编辑 myvalues.yaml 文件,参考配置项说明:
- 安装 fogcloud-charts
kubectl create namespace {NAMESPACE_NAME} helm install -f myvalues.yaml {RELEASE_NAME} --set namespace={NAMESPACE_NAME} ./fogcloud-charts
- 升级 fogcloud-charts
helm upgrade -f myvalues.yaml {RELEASE_NAME} ./fogcloud-charts
配置说明:
配置项 | 类型 | 说明 |
k8sApiServer | string | k8s server api 地址,用来创建 k8s StatefulSet 资源;可以通过 获取 |
ingress.hosts.webAdmin | string | 使用 ingress 方式发布对外服务时,用于设置管理后台域名 |
ingress.hosts.api | string | 使用 ingress 方式发布对外服务时,用于设置后端 api 服务域名 |
ingress.tls.enabled | bool | 是否启用 ingress tls |
ingress.tls.webAdmin.createWithCertFile | bool | 是否使用证书文件创建管理后台 web 服务的 sercret 对象;若为 true,可将.crt(证书), .key(密钥)文件放到 fogcloud-charts/configs/cert/webAdmin 目录下 |
mqttBroker.enabled | bool | 是否使用 k8s 创建 mqtt broker |
mqttBroker.tls.enabled | bool | mqtt 应用是否启用 tls |
mqttBroker.tls.createWithCertFile | bool | 是否使用证书文件创建 mqtt 应用的 sercret 对象,启用 mqttBroker.tls 时有效;若为 true,可将.crt(证书), .key(密钥)文件放到 fogcloud-charts/configs/cert/mqtt 目录下 |
rabbitmq.enabled | bool | 是否使用 k8s 创建 rabbitmq |
rabbitmq.tls.enabled | bool | rabbitmq 是否启用 tls |
rabbitmq.tls.createWithCertFile | bool | 是否使用证书文件创建 rabbitmq 的 sercret 对象,启用 rabbitmq.tls 时有效;若为 true,可将.crt(证书), .key(密钥)文件放到 fogcloud-charts/configs/cert/amqp 目录下 |
postgres.enabled | bool | 是否使用 k8s 创建 postgresql 应用(生产环境建议单独部署数据库应用) |
mongodb.enabled | bool | 是否使用 k8s 创建 mongodb 应用 |
redis.enabled | bool | 是否使用 k8s 创建 redis 应用 |
etcd.enabled | bool | 是否使用 k8s 创建 etcd |
minio.enabled | bool | 是否使用 k8s 创建 minio |
# 3.4 卸载 chart
helm uninstall fogcloud