LangFuse 安装说明(K8s)

生产级部署,通常会采用K8s进行部署,下面将说明讲述部署的方法。

安装要求:Postgres 数据库

Langfuse 需要一个持久的 Postgres 数据库来存储其状态。您可以使用 AWS、Azure 或 GCP 上的托管服务,也可以自行托管。数据库准备就绪后,请将连接字符串放在手边。

部署应用程序

K8s 部署脚本:langfuse-server.yaml
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: langfuse-cm
  annotations:
    kubesphere.io/creator: admin
data:
  db.url: >-
    postgresql://<user>:<password>@<host>:<port>/<dbname>
  db.export.pagesize: 1000
  nextauth.url: 'http://localhost:3000'
  nextauth.secret: mysecret
  salt: mysalt
  bind.port: 3000
  bind.hostname: localhost
  next_public_sign_up_disabled: false
  auth_domains_with_sso_enforcement: ''
  auth_disable_username_password: false
  langfuse-server.default_project_id: ''
  langfuse-server.default_project_role: 'VIEWER'
  smtp.connection_url: ''
  smtp.email_from_address: ''
  s3.endpoint: ''
  s3.access_key_id: ''
  s3.secret_access_key: ''
  s3.bucket_name: ''
  s3.region: ''
---
apiVersion: v1
kind: Service
metadata:
  name: langfuse-server-svc
  annotations:
    kubesphere.io/alias-name: LangFuse 服务
    kubesphere.io/description: LangFuse 服务
spec:
  ports:
    - name: tcp-3000
      port: 3000
      protocol: TCP
      targetPort: 3000
  selector:
    app: langfuse-server
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: langfuse-server-deploy
  annotations:
    kubesphere.io/alias-name: LangFuse 服务
    kubesphere.io/description: LangFuse 服务
  labels:
    app: langfuse-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: langfuse-server
  template:
    metadata:
      labels:
        app: langfuse-server
    spec:
      containers:
        - name: langfuse-server
          image: 'ghcr.io/langfuse/langfuse:latest'
          ports:
            - name: http-3000
              containerPort: 3000
              protocol: TCP
          env:
            - name: DATABASE_URL
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: db.url
            - name: NEXTAUTH_URL
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: nextauth.url
            - name: NEXTAUTH_SECRET
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: nextauth.secret
            - name: SALT
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: salt
            - name: PORT
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: bind.port
            - name: HOSTNAME
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: bind.hostname
            - name: NEXT_PUBLIC_SIGN_UP_DISABLED
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: next_public_sign_up_disabled
            - name: AUTH_DOMAINS_WITH_SSO_ENFORCEMENT
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: auth_domains_with_sso_enforcement
            - name: AUTH_DISABLE_USERNAME_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: auth_disable_username_password
            - name: LANGFUSE_DEFAULT_PROJECT_ID
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: langfuse-server.default_project_id
            - name: LANGFUSE_DEFAULT_PROJECT_ROLE
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: langfuse-server.default_project_role
            - name: SMTP_CONNECTION_URL
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: smtp.connection_url
            - name: EMAIL_FROM_ADDRESS
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: smtp.email_from_address
            - name: S3_ENDPOINT
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: s3.endpoint
            - name: S3_ACCESS_KEY_ID
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: s3.access_key_id
            - name: S3_SECRET_ACCESS_KEY
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: s3.secret_access_key
            - name: S3_BUCKET_NAME
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: s3.bucket_name
            - name: S3_REGION
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: s3.region
            - name: DB_EXPORT_PAGE_SIZE
              valueFrom:
                configMapKeyRef:
                  name: langfuse-cm
                  key: db.export.pagesize
          imagePullPolicy: Always
使用 kubectl 执行如下命令部署 LangFuse 服务 :
#kubectl create -f langfuse-server.yaml --namespace=你的命名空间
kubectl create -f langfuse-server.yaml --namespace=default
作者:Jeebiz  创建时间:2024-03-20 13:13
最后编辑:Jeebiz  更新时间:2024-03-22 00:12