前言
基于FastGPT官方的docker-compose.yaml文件手搓了一份在k8s环境部署的配置文件。
环境准备
- k8s集群(我用的是1.20.6)
- 足够的存储和计算资源( 这里根据自己的需求来)
准备配置文件
pv.yaml
# PersistentVolumes
apiVersion: v1
kind: PersistentVolume
metadata:
name: pg-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/mnt/data/pg"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongo-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/mnt/data/mongo"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/mnt/data/mysql"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: oneapi-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/mnt/data/oneapi"
pvc.yaml
# PersistentVolumeClaims
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pg-pvc
namespace: louis-ai
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
volumeName: pg-pv
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-pvc
namespace: louis-ai
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
volumeName: mongo-pv
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
namespace: louis-ai
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
volumeName: mysql-pv
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: oneapi-pvc
namespace: louis-ai
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
volumeName: oneapi-pv
oneapi.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: oneapi
namespace: louis-ai
spec:
selector:
matchLabels:
app: oneapi
replicas: 1
template:
metadata:
labels:
app: oneapi
spec:
containers:
- name: oneapi
image: ghcr.io/songquanpeng/one-api:latest
ports:
- containerPort: 3000
env:
- name: SQL_DSN
value: "root:oneapimmysql@tcp(mysql:3306)/oneapi"
- name: SESSION_SECRET
value: "oneapikey"
- name: MEMORY_CACHE_ENABLED
value: "true"
- name: BATCH_UPDATE_ENABLED
value: "true"
- name: BATCH_UPDATE_INTERVAL
value: "10"
- name: INITIAL_ROOT_TOKEN
value: "fastgpt"
volumeMounts:
- mountPath: /var/lib/oneapi/data
name: oneapi-pvc
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 50m
memory: 51Mi
volumes:
- name: oneapi-pvc
persistentVolumeClaim:
claimName: oneapi-pvc
---
apiVersion: v1
kind: Service
metadata:
name: oneapi
namespace: louis-ai
spec:
type: NodePort
ports:
- port: 3001
targetPort: 3000
selector:
app: oneapi
mysql.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
namespace: louis-ai
spec:
selector:
matchLabels:
app: mysql
replicas: 1
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: docker.m.daocloud.io/mysql:8.0.36
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "oneapimmysql"
- name: MYSQL_DATABASE
value: "oneapi"
volumeMounts:
- mountPath: /var/lib/mysql
name: mysql-pvc
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 250m
memory: 512Mi
volumes:
- name: mysql-pvc
persistentVolumeClaim:
claimName: mysql-pvc
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: louis-ai
spec:
ports:
- port: 3306
selector:
app: mysql
fastgpt.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sandbox
namespace: louis-ai
spec:
selector:
matchLabels:
app: sandbox
replicas: 1
template:
metadata:
labels:
app: sandbox
spec:
containers:
- name: sandbox
image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-sandbox:v4.8.3
ports:
- containerPort: 3000
resources:
limits:
cpu: 1000m
memory: 1024Mi
requests:
cpu: 250m
memory: 512Mi
---
apiVersion: v1
kind: Service
metadata:
name: sandbox
namespace: louis-ai
spec:
ports:
- port: 3000
selector:
app: sandbox
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: fastgpt
namespace: louis-ai
spec:
selector:
matchLabels:
app: fastgpt
replicas: 1
template:
metadata:
labels:
app: fastgpt
spec:
containers:
- name: fastgpt
image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.3
ports:
- containerPort: 3000
env:
- name: DEFAULT_ROOT_PSW
value: "1234"
- name: OPENAI_BASE_URL
value: "http://oneapi.louis-ai.svc.cluster.local:3001/v1" #这里是oneapi的集群地址
- name: CHAT_API_KEY
value: "sk-" #oneapi的令牌
- name: DB_MAX_LINK
value: "30"
- name: TOKEN_KEY
value: "any"
- name: ROOT_KEY
value: "root_key"
- name: FILE_TOKEN_KEY
value: "filetoken"
- name: MONGODB_URI
value: "mongodb://root:123456@mongo:27017/fastgpt?authSource=admin"
- name: PG_URL
value: "postgresql://username:password@pg:5432/postgres"
- name: SANDBOX_URL
value: "http://sandbox.louis-ai.svc.cluster.local:3000" #这里需要改成集群地址
volumeMounts:
- mountPath: /app/data/config.json
name: config-volume
subPath: config.json
resources:
limits:
cpu: 1000m
memory: 1024Mi
requests:
cpu: 250m
memory: 512Mi
volumes:
- name: config-volume
configMap:
name: fastgpt-config
---
apiVersion: v1
kind: Service
metadata:
name: fastgpt
namespace: louis-ai
spec:
type: NodePort
ports:
- port: 3000
selector:
app: fastgpt
---
apiVersion: v1
kind: ConfigMap
metadata:
name: fastgpt-config
namespace: louis-ai
data:
config.json: |
{
"feConfigs": {
"lafEnv": "https://laf.dev"
},
"systemEnv": {
"openapiPrefix": "fastgpt",
"vectorMaxProcess": 15,
"qaMaxProcess": 15,
"pgHNSWEfSearch": 100
},
"llmModels": [
{
"model": "qwen-max",
"name": "qwen",
"maxContext": 16000,
"avatar": "/imgs/model/openai.svg",
"maxResponse": 4000,
"quoteMaxToken": 13000,
"maxTemperature": 1.2,
"charsPointsPrice": 0,
"censor": false,
"vision": false,
"datasetProcess": true,
"usedInClassify": true,
"usedInExtractFields": true,
"usedInToolCall": true,
"usedInQueryExtension": true,
"toolChoice": true,
"functionCall": true,
"customCQPrompt": "",
"customExtractPrompt": "",
"defaultSystemChatPrompt": "",
"defaultConfig": {}
},
{
"model": "gpt-4-0125-preview",
"name": "gpt-4-turbo",
"avatar": "/imgs/model/openai.svg",
"maxContext": 125000,
"maxResponse": 4000,
"quoteMaxToken": 100000,
"maxTemperature": 1.2,
"charsPointsPrice": 0,
"censor": false,
"vision": false,
"datasetProcess": false,
"usedInClassify": true,
"usedInExtractFields": true,
"usedInToolCall": true,
"usedInQueryExtension": true,
"toolChoice": true,
"functionCall": false,
"customCQPrompt": "",
"customExtractPrompt": "",
"defaultSystemChatPrompt": "",
"defaultConfig": {}
},
{
"model": "gpt-4-vision-preview",
"name": "gpt-4-vision",
"avatar": "/imgs/model/openai.svg",
"maxContext": 128000,
"maxResponse": 4000,
"quoteMaxToken": 100000,
"maxTemperature": 1.2,
"charsPointsPrice": 0,
"censor": false,
"vision": true,
"datasetProcess": false,
"usedInClassify": false,
"usedInExtractFields": false,
"usedInToolCall": false,
"usedInQueryExtension": false,
"toolChoice": true,
"functionCall": false,
"customCQPrompt": "",
"customExtractPrompt": "",
"defaultSystemChatPrompt": "",
"defaultConfig": {}
}
],
"vectorModels":[
{
"model": "text-embedding-ada-002",
"name": "Embedding-2",
"avatar": "/imgs/model/openai.svg",
"charsPointsPrice": 0,
"defaultToken": 512,
"maxToken": 3000,
"weight": 100,
"dbConfig": {},
"queryConfig": {}
},
{
"model": "text-embedding-v1",
"name": "Embedding-1",
"avatar": "/imgs/model/openai.svg",
"charsPointsPrice": 0,
"defaultToken": 512,
"maxToken": 3000,
"weight": 100,
"dbConfig": {},
"queryConfig": {}
}
],
"reRankModels": [],
"audioSpeechModels": [
{
"model": "tts-1",
"name": "OpenAI TTS1",
"charsPointsPrice": 0,
"voices": [
{
"label": "Alloy",
"value": "alloy",
"bufferId": "openai-Alloy"
},
{
"label": "Echo",
"value": "echo",
"bufferId": "openai-Echo"
},
{
"label": "Fable",
"value": "fable",
"bufferId": "openai-Fable"
},
{
"label": "Onyx",
"value": "onyx",
"bufferId": "openai-Onyx"
},
{
"label": "Nova",
"value": "nova",
"bufferId": "openai-Nova"
},
{
"label": "Shimmer",
"value": "shimmer",
"bufferId": "openai-Shimmer"
}
]
}
],
"whisperModel": {
"model": "whisper-1",
"name": "Whisper1",
"charsPointsPrice": 0
}
}
mongo.yaml
apiVersion: v1
kind: Service
metadata:
name: mongo
namespace: louis-ai
spec:
ports:
- port: 27017
name: mongo
clusterIP: None
selector:
app: mongo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo
namespace: louis-ai
spec:
replicas: 1
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
containers:
- name: mongo
image: registry.cn-hangzhou.aliyuncs.com/fastgpt/mongo:5.0.18 # 使用 Docker Hub 镜像
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/mongo:5.0.18 # 使用阿里云镜像
# image: mongo:4.4.29 # CPU 不支持 AVX 时使用
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: "root"
- name: MONGO_INITDB_ROOT_PASSWORD
value: "123456"
volumeMounts:
- name: mongo-init-scripts
mountPath: /docker-entrypoint-initdb.d
resources:
limits:
cpu: 1000m
memory: 1024Mi
requests:
cpu: 250m
memory: 250Mi
command:
- bash
- -c
- |
if [ ! -f /data/mongodb.key ]; then
openssl rand -base64 128 > /data/mongodb.key
chmod 400 /data/mongodb.key
chown 999:999 /data/mongodb.key
fi
if [ ! -f /data/initReplicaSet.js ]; then
echo 'const isInited = rs.status().ok === 1
if(!isInited){
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "mongo:27017" }
]
})
}' > /data/initReplicaSet.js
fi
exec docker-entrypoint.sh mongod --keyFile /data/mongodb.key --replSet rs0 &
until mongo -u root -p 123456 --authenticationDatabase admin --eval "print('waited for connection')" > /dev/null 2>&1; do
echo "Waiting for MongoDB to start..."
sleep 2
done
mongo -u root -p 123456 --authenticationDatabase admin /data/initReplicaSet.js
wait $!
volumes:
- name: mongo-init-scripts
emptyDir: {}
- name: mongo-pvc
persistentVolumeClaim:
claimName: mongo-pvc
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mongo-keyfile
namespace: louis-ai
data:
mongodb.key: |
# 初始值为空,容器启动时将生成密钥文件
pg.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: pg
namespace: louis-ai
spec:
replicas: 1
selector:
matchLabels:
app: pg
template:
metadata:
labels:
app: pg
spec:
containers:
- name: pg
image: registry.cn-hangzhou.aliyuncs.com/fastgpt/pgvector:v0.7.0
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
value: "username"
- name: POSTGRES_PASSWORD
value: "password"
- name: POSTGRES_DB
value: "postgres"
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: pg-pvc
resources:
limits:
cpu: 1000m
memory: 1024Mi
requests:
cpu: 250m
memory: 250Mi
volumes:
- name: pg-pvc
persistentVolumeClaim:
claimName: pg-pvc
---
apiVersion: v1
kind: Service
metadata:
name: pg
namespace: louis-ai
spec:
ports:
- port: 5432
selector:
app: pg
应用配置文件
-
将以上所有文件拉入集群
-
更改fastgpt的配置文件,填入oneapi,sandbox的集群地址和令牌
-
应用所有配置文件
kubectl apply -f .
-
检查集群状态
kubectl get pod -n louis-ai