# 系统部署
注意:文章所有涉及的 docker 镜像和仓库(gchr.io / helm) 等,目前未正式对外开放;
如需试用,请联系我们 (opens new window)的销售获取。
foglcoud 依赖以下第三方服务:
- minio
- redis
- mongodb
- postgresql
- etcd
- rabbitmq
- emqx
- hmq
本文部署方式只列举 fogcloud 自身服务,包括:
- fogcloud(后台主服务)
- fogcloud-web(前端服务)
- fogcron-scheduler(定时器调度服务)
- faasbuilder(云函数镜像编译服务)
完整部署方式请参考 helm 方式
# 1 通过 docker 部署
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
# 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:lastest 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 部署
- chart 包下载
curl https://github.com/fogcloud-io/fogcloud-charts/releases/tag/v0.1.0
- 安装 chart 包
helm install fogcloud ./fogcloud-charts