diff --git a/docs/en/solutions/How_to_install_and_use_Langflow.md b/docs/en/solutions/How_to_install_and_use_Langflow.md index 061344fb2..7e4a47e5b 100644 --- a/docs/en/solutions/How_to_install_and_use_Langflow.md +++ b/docs/en/solutions/How_to_install_and_use_Langflow.md @@ -37,76 +37,111 @@ This section provides detailed instructions on how to deploy Langflow to a Kuber ## Publishing -Download the Langflow installation file: `langflow.ALL.v1.6.4-1.tgz` +Download the Langflow installation file: `langflow-operator.alpha.ALL.v1.10.1.tgz` Use the violet command to publish to the platform repository: ```bash -violet push --platform-address=platform-access-address --platform-username=platform-admin --platform-password=platform-admin-password langflow.ALL.v1.6.4-1.tgz +violet push --platform-address=platform-access-address --platform-username=platform-admin --platform-password=platform-admin-password langflow-operator.alpha.ALL.v1.10.1.tgz ``` +Starting with v1.10.1, Langflow is installed via `OperatorHub` and a `Langflow` custom resource, not from the Applications / Catalog form. + ## Deployment ### Prepare Storage -Langflow supports two database modes: -- **SQLite (Default)**: For development and testing, data is stored in persistent volumes -- **PostgreSQL (Recommended)**: For production environments, providing better performance and scalability - -The cluster needs to have CSI pre-installed or `PersistentVolume` pre-prepared. +Langflow uses SQLite by default with an RWO PVC (1Gi). For production, PostgreSQL is recommended (see [Configure Database](#2-configure-database)). The StorageClass for the SQLite PVC is configured under `spec.langflow.backend.sqlite.volume` — see [Configure Storage](#1-configure-storage) for details. -### Prepare Database +### Prepare Database (Optional) #### Using SQLite (Default) -SQLite is Langflow's default database, suitable for development and testing environments: -- Data is stored in persistent volumes -- Simple configuration, no additional setup required -- Supports single-instance deployment - -#### Using PostgreSQL (Recommended) +SQLite is Langflow's default database: +- Data is stored in an RWO PVC (`data-langflow-service-0`, 1Gi default) +- Simple, no additional infrastructure +- Only supports single-instance backend (StatefulSet replicas = 1) -Production environments strongly recommend using PostgreSQL for better performance and scalability: +#### Using PostgreSQL (Recommended for production) -The `PostgreSQL operator` provided by `Data Services` can be used to create a `PostgreSQL cluster`. +Production environments strongly recommend PostgreSQL: -Check the access address and password in the `PostgreSQL` instance details in `Data Services`. +- Provision a PostgreSQL instance via `Data Services` PostgreSQL Operator, or use any external PostgreSQL reachable from the cluster. +- Create a dedicated database and user with `CREATE`/`CONNECT` privileges. The Langflow backend will run Alembic migrations against it at first startup. **Note**: - PostgreSQL version 12 or higher is recommended -- Need to create a separate database and user -- Ensure network connectivity +- Ensure network connectivity from the Langflow namespace to the PostgreSQL instance +- Store the password in a Kubernetes `Secret` and reference it via `secretKeyRef` (see [Configure Database](#2-configure-database)) -### Create Application +### Install Operator + Create Langflow -1. Go to the `Alauda Container Platform` view and select the namespace where Langflow will be deployed. +1. In `Alauda Container Platform`, open `OperatorHub` and search for `Langflow`. Install `Langflow` from the `platform` catalog source (defaults: channel `alpha`, install mode `AllNamespaces`). -2. In the left navigation, select `Applications` / `Applications`, then click the `Create` button on the right page. +2. Wait for the CSV `langflow-operator.v1.10.1` to reach `Succeeded`. -3. In the popup dialog, select `Create from Catalog`, then the page will jump to the `Catalog` view. +3. Create a namespace for the Langflow instance (default suggestion: `langflow-system`). -4. Find `3rdparty/chart-langflow` and click `Create` to create this application. +4. Apply a `Langflow` custom resource in that namespace. Minimal form: -5. On the `Catalog` / `Create langflow` form, fill in the `Name` (recommended as `langflow`) and `Custom` configuration in `Values`, then click the `Create` button to complete creation. The `Custom` content will be described below. It can also be modified after creation through the `Update` application method. + ```yaml + apiVersion: langflow-operator.alauda.io/v1 + kind: Langflow + metadata: + name: langflow + namespace: langflow-system + spec: {} + ``` + + Empty `spec: {}` uses defaults (SQLite on the cluster default StorageClass, IDE mode, ClusterIP Services only). To customize, add fields under `spec.langflow.*` per the sections below. ## Configuration -Users can modify the `Custom Values` of the `Application` to adjust configuration. The main configurations to focus on are as follows: +The `Langflow` custom resource's `spec.langflow.*` fields customize the deployment. The main configurations to focus on are as follows. + +> **⚠ Array fields REPLACE chart defaults, they do not append.** +> When you set `spec.langflow.backend.volumes` (or `.volumeMounts`), the chart drops its own default `tmp` / `data` / `db` / `flows` `emptyDir` volumes and uses only what you provide. If you add a custom volume without re-declaring the defaults, the backend container will crash on startup with `FileNotFoundError: No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/app']` (the Langflow entrypoint imports `dill`, which calls `tempfile.gettempdir()` — `readOnlyRootFilesystem: true` means `/tmp` must be a writable volume). +> +> If you customize `volumes` or `volumeMounts`, keep the four chart-default entries alongside your additions. Suggested minimal boilerplate: +> +> ```yaml +> spec: +> langflow: +> backend: +> volumes: +> - {name: langflow-tmp, emptyDir: {}} # /tmp — required (readOnly root FS) +> - {name: app-data, emptyDir: {}} # /app/data — chart default +> - {name: app-db, emptyDir: {}} # /app/db — chart default +> - {name: app-flows, emptyDir: {}} # /app/flows — chart default +> # ... your additions below +> volumeMounts: +> - {name: langflow-tmp, mountPath: /tmp} +> - {name: app-data, mountPath: /app/data} +> - {name: app-db, mountPath: /app/db} +> - {name: app-flows, mountPath: /app/flows} +> # ... your additions below +> ``` +> +> Sections below that add custom `volumes` (ConfigMap flow import, local models, Python deps) omit this boilerplate for brevity — remember to include it. This trap was caught live on ACP 4.3 during doc validation. ### 1. Configure Storage #### 1.1 Configure SQLite Storage (Default) -The storage class and size can be specified by adding the following configuration: +The StorageClass and volume size can be specified by adding the following configuration: ```yaml -langflow: - sqlite: - volume: - storageClassName: storage-class-name # Replace with the actual storage class name - size: 1Gi # Replace with the actual required space size +spec: + langflow: + backend: + sqlite: + volume: + existingStorageClassName: # Cluster StorageClass name; leave "default" to use the cluster default + size: 1Gi # PVC size ``` -**Note**: When using SQLite, only single-instance deployment (replicaCount = 1) is supported. +**Note**: +- `existingStorageClassName: "default"` is a magic string in the chart that means "use the cluster's default StorageClass" (i.e. the SC annotated `storageclass.kubernetes.io/is-default-class: "true"`). Set an explicit SC name to override. +- When using SQLite, only single-instance backend is supported (StatefulSet replicas = 1). ### 2. Configure Database @@ -115,168 +150,203 @@ langflow: PostgreSQL access information can be configured by setting the following fields: ```yaml -langflow: - externalDatabase: - enabled: true # Enable external database - driver: - value: "postgresql" - host: - value: postgres-host # PostgreSQL access address - port: - value: "5432" # PostgreSQL access port, default: 5432 - database: - value: langflow # Database name, note: database will be created automatically - user: - value: langflow # Database username - password: - valueFrom: - secretKeyRef: - name: postgres-secret # Secret name storing database access password - key: password # Secret key storing database access password +spec: + langflow: + backend: + externalDatabase: + enabled: true # Enable external database + driver: {value: "postgresql"} + host: {value: } # PostgreSQL host (Service DNS or external address) + port: {value: "5432"} + database: {value: langflow} # Target database (must exist before backend starts) + user: {value: langflow} + password: + valueFrom: + secretKeyRef: + name: postgres-secret # Secret holding the password + key: password ``` -**Note**: Due to temporary storage limitations, the current version temporarily does not support multi-instance deployment. Even with PostgreSQL database configured, only single-instance deployment (replicaCount = 1) is supported. +The chart runs a small startup shim inside the backend container that reads these `LF_CHART_EXTERNALDB_*` env vars and composes them into `LANGFLOW_DATABASE_URL=postgresql://:@:/`, overriding the sqlite default. Verified by connecting to the target PostgreSQL after backend startup: Langflow creates its full schema (`alembic_version`, `flow`, `apikey`, `folder`, `message`, etc.) via Alembic and populates it with the built-in starter projects. -### 3. Configure Access Method +**Note**: With SQLite, only single-instance backend is supported. Multi-instance backend requires PostgreSQL, but the current chart still ships `replicas: 1` for the backend StatefulSet — scale explicitly if you need HA. -By default, `LoadBalancer` is used to provide access address. +### 3. Configure External Access -#### 3.1 Modify Service Type +Langflow creates only two `ClusterIP` Services by default: -The `Service` type can be modified by setting the following fields: +- `langflow-service` on port 8080 — frontend (React IDE served by nginx) +- `langflow-service-backend` on port 7860 — backend (FastAPI + `/api/v1/*`) -```yaml -langflow: - service: - type: LoadBalancer # Can be changed to NodePort or ClusterIP - port: 7860 # Service port -``` - -#### 3.2 Enable Ingress +The frontend nginx also reverse-proxies `/api`, `/health` and `/health_check` to the backend, so **routing all external traffic to `langflow-service:8080` gives users both the IDE and the backend API through the same entry point**. -Ingress can be configured by setting the following fields. After enabling Ingress, the Service type is usually changed to ClusterIP: +External access is provided via Gateway API (Envoy Gateway). Apply the three resources below in the same namespace as your `Langflow` custom resource. Adjust the `gatewayClassName` (`envoy-gateway-system-aieg` is the default on Alauda Container Platform 4.3+) and the `hostname` to match your environment. ```yaml -ingress: - enabled: true # Enable Ingress functionality - hosts: - - host: langflow.example.com # Access domain (must be DNS name, not IP address) - paths: - - path: / - tls: - - secretName: langflow-tls # Secret name storing TLS certificate - hosts: - - langflow.example.com +# ── 1) EnvoyProxy: expose the data plane via NodePort (or LoadBalancer if available). ──── +apiVersion: gateway.envoyproxy.io/v1alpha1 +kind: EnvoyProxy +metadata: + name: langflow-proxy + namespace: +spec: + logging: {level: {default: warn}} + provider: + type: Kubernetes + kubernetes: + envoyService: + type: NodePort # change to LoadBalancer if the cluster has one + externalTrafficPolicy: Cluster +--- +# ── 2) Gateway: HTTP listener; add an HTTPS listener with a cert Secret for TLS. ───────── +apiVersion: gateway.networking.k8s.io/v1 +kind: Gateway +metadata: + name: langflow-gw + namespace: +spec: + gatewayClassName: envoy-gateway-system-aieg + infrastructure: + parametersRef: + group: gateway.envoyproxy.io + kind: EnvoyProxy + name: langflow-proxy + listeners: + - name: http + protocol: HTTP + port: 80 + allowedRoutes: {namespaces: {from: Same}} +--- +# ── 3) HTTPRoute: all paths → langflow-service:8080; nginx fans out /api* to backend. ──── +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: langflow + namespace: +spec: + parentRefs: + - {group: gateway.networking.k8s.io, kind: Gateway, name: langflow-gw} + # hostnames: [langflow.example.com] # optional; omit to accept any Host + rules: + - matches: [{path: {type: PathPrefix, value: "/"}}] + backendRefs: + - {name: langflow-service, port: 8080} ``` -### 4. Configure Authentication and User Management (Optional) - -#### 4.1 Enable User Authentication - -User authentication can be enabled by setting the following fields: +After apply, wait for the `Gateway` to reach `PROGRAMMED=True`, then find the NodePort that Envoy Gateway allocated: -```yaml -langflow: - auth: - enabled: true # Enable authentication - superuser: - username: langflow # Superuser name - password: "" # Superuser password, auto-generated if not set - secretKey: "" # Secret key, auto-generated if not set - newUserActive: false # Whether new users need activation - enableSuperuserCLI: false # Whether to enable CLI superuser - accessTokenExpireSeconds: 3600 # Access token expiration time (seconds) - refreshTokenExpireSeconds: 604800 # Refresh token expiration time (seconds) +```bash +kubectl get gateway langflow-gw -n +kubectl get svc -A -l gateway.envoyproxy.io/owning-gateway-name=langflow-gw ``` -After enabling authentication, by default: -- Login is required to access -- Superuser can be configured -- New users can only be added by superuser through `/admin` page (self-registration is not supported) -- New user account activation: If `newUserActive=true`, new user accounts are automatically activated; If `newUserActive=false` (default), superuser needs to manually activate +The NodePort service in the output is the entry point — reach Langflow at `http://:/`. +If you added an HTTPS listener with a certificate `Secret` in a different namespace, you'll also need a `ReferenceGrant` from the Gateway's namespace to the certificate's namespace. -### 5. Configure OAuth2 Proxy (Optional) +### 4. Configure Authentication and User Management (Optional) -OAuth2 proxy can be configured to provide single sign-on functionality by setting the following fields: +Langflow authentication is controlled by environment variables on the backend container. Set them under `spec.langflow.backend.env`: ```yaml -oauth2_proxy: - enabled: true # Enable OAuth2 proxy - oidcIssuer: "https://x.x.x.com/dex" # OIDC Issuer address - oidcClientID: "your-client-id" # OIDC client ID - oidcClientSecret: "your-client-secret" # OIDC client secret (recommended to use Secret) +spec: + langflow: + backend: + env: + - name: LANGFLOW_AUTO_LOGIN + value: "false" # Disable auto-login (default: true) + - name: LANGFLOW_SUPERUSER + valueFrom: + secretKeyRef: {name: langflow-superuser, key: username} + - name: LANGFLOW_SUPERUSER_PASSWORD + valueFrom: + secretKeyRef: {name: langflow-superuser, key: password} + - name: LANGFLOW_NEW_USER_IS_ACTIVE + value: "false" # New users require superuser activation (default: false) + - name: LANGFLOW_ENABLE_SUPERUSER_CLI + value: "false" # Disable CLI superuser bootstrap ``` -To configure `Alauda Container Platform` as OIDC Provider, configure as follows: -- `oauth2_proxy.oidcIssuer` is the platform access address plus `/dex` -- `oauth2_proxy.oidcClientID` is fixed as `langflow` -- `oauth2_proxy.oidcClientSecret` is fixed as `ZXhhbXBsZS1hcHAtc2VjcmV0` +**Verify the login flow in a browser**: -Also create an OAuth2Client resource in the global cluster to configure Langflow's client information: +1. **Open the Langflow URL in a fresh browser tab** — use an Incognito / Private window, or clear the site's cookies first (DevTools → Application → Cookies → delete `access_token_lf`, `refresh_token_lf`, `apikey_tkn_lflw`). Without this step, previously issued auto-login cookies keep working until they expire, and the browser walks straight into the IDE as if authentication were still off. +2. **The page should show a login form** instead of loading the IDE directly. +3. **Log in with the superuser credentials** you set in `LANGFLOW_SUPERUSER` / `LANGFLOW_SUPERUSER_PASSWORD`. You should land in the IDE with your username shown in the top-right menu; entering a wrong password should keep you on the login page with an error message. -```yaml -apiVersion: dex.coreos.com/v1 -kind: OAuth2Client -metadata: - name: nrqw4z3gnrxxps7sttsiiirdeu - namespace: cpaas-system -id: langflow # Consistent with oauth2_proxy.oidcClientID in values -name: Langflow -secret: ZXhhbXBsZS1hcHAtc2VjcmV0 # Consistent with oauth2_proxy.oidcClientSecret in values -redirectURIs: -- http://xxx.xxx.xxxx.xxx:xxxxx/* # OAuth2-Proxy access address, acquisition method described below - # If multiple Langflow instances are deployed, add multiple access addresses here -``` +Notes: -**Note**: OAuth2 Proxy access address can be obtained from the `-oauth2-proxy` Service, use the appropriate access method based on Service type. +- Self-registration is not supported when `LANGFLOW_AUTO_LOGIN=false`. New users must be added by the superuser from the admin page; if `LANGFLOW_NEW_USER_IS_ACTIVE=false`, the superuser must also activate each new account before the user can log in. +- The superuser credentials are consumed on **first startup only**. Once written into the database, changing the env vars alone does not rotate the password — update it through Langflow's admin UI instead. Rotating requires either editing the existing user or wiping the database and restarting. +- Access/refresh token expiration are controlled by `LANGFLOW_ACCESS_TOKEN_EXPIRE_SECONDS` (default 30 days) and `LANGFLOW_REFRESH_TOKEN_EXPIRE_SECONDS` (default 60 days). For production, shorter values are recommended: + ```yaml + env: + - {name: LANGFLOW_ACCESS_TOKEN_EXPIRE_SECONDS, value: "3600"} # 1 hour + - {name: LANGFLOW_REFRESH_TOKEN_EXPIRE_SECONDS, value: "604800"} # 7 days + ``` -After enabling OAuth2 Proxy, it is recommended to: -- Set `langflow.service.type` to `ClusterIP`, allowing access only within the cluster. Users need to access Langflow through OAuth2 Proxy address. -- Set `langflow.auth.enabled` to `false`. Use OAuth2 Proxy to handle login authentication. +### 5. Configure Runtime Mode (Backend-Only) -Users can log out by accessing `/oauth2/sign_out`. +Runtime mode drops the React IDE frontend and runs only the backend REST API. This is the recommended deployment shape for production API-serving scenarios. -### 6. Configure Runtime Mode (Backend-Only) +#### 5.1 Enable Runtime Mode -Runtime mode is the recommended deployment method for production environments, deploying only the Langflow backend API service without a visual interface. +Two fields together enable full runtime mode: -#### 6.1 Enable Runtime Mode +- `spec.langflow.backend.backendOnly: true` — starts the backend with `--backend-only` (backend is already the default in the current chart, but keep this explicit). +- `spec.langflow.frontend.enabled: false` — the chart skips the frontend Deployment entirely (verified: `kubectl get deploy -n ` returns 0 resources; only the backend StatefulSet remains). -Runtime mode (backend-only) can be enabled by setting the following fields: +Optionally auto-import flows from a PVC or ConfigMap. **Remember the [chart-defaults boilerplate](#configuration)** — mount the flows source under a distinct path (`/app/loaded-flows`) so it doesn't collide with the chart's own `/app/flows` `emptyDir`: ```yaml -langflow: - backendOnly: true # Enable backend-only mode - env: - - name: LANGFLOW_LOAD_FLOWS_PATH # Set the path to load Flows - value: "/app/flows" - volumes: - - name: flows # Load Flows content through volume - persistentVolumeClaim: # From PVC or other volumes - claimName: langflow-flows-pvc - volumeMounts: # Mount volume to specified path - - name: flows - mountPath: /app/flows +spec: + langflow: + backend: + backendOnly: true + env: + - name: LANGFLOW_LOAD_FLOWS_PATH + value: "/app/loaded-flows" + volumes: + - {name: langflow-tmp, emptyDir: {}} + - {name: app-data, emptyDir: {}} + - {name: app-db, emptyDir: {}} + - {name: app-flows, emptyDir: {}} + - name: loaded-flows + persistentVolumeClaim: {claimName: langflow-flows-pvc} + volumeMounts: + - {name: langflow-tmp, mountPath: /tmp} + - {name: app-data, mountPath: /app/data} + - {name: app-db, mountPath: /app/db} + - {name: app-flows, mountPath: /app/flows} + - name: loaded-flows + mountPath: /app/loaded-flows + frontend: + enabled: false ``` -When enabling `LANGFLOW_LOAD_FLOWS_PATH`, authentication must be disabled, i.e., `langflow.auth.enabled` must be set to `false`. + +When enabling `LANGFLOW_LOAD_FLOWS_PATH`, keep `LANGFLOW_AUTO_LOGIN=true` (auto-login mode) — this is a Langflow constraint: user-owned auto-imported flows require the auto-login default user to be present. ## Access Address -### 1. Access via Service +### 1. Access via Gateway API (recommended) -`Langflow` provides external access through `Service`. Check its `Service` to get the access address. +When the Gateway API path from [Configure External Access](#3-configure-external-access) is applied, the assigned NodePort or LoadBalancer address of the Gateway's data-plane Service is the entry point. Example: -- If OAuth2 proxy is not enabled, Service name is: `` -- If OAuth2 proxy is enabled, Service name is: `-oauth2-proxy` +```bash +# Discover the envoy data-plane Service's NodePort (or LoadBalancer address) +kubectl get svc -A -l gateway.envoyproxy.io/owning-gateway-name=langflow-gw -If the `Service` type is `LoadBalancer` and the load balancer controller in the environment has assigned an access address, please access through that address. +# Reach Langflow through any cluster node's IP + that NodePort +curl http://:/health_check +# Or open http://:/ in a browser to see the Langflow IDE +``` -If the `Service` type is `LoadBalancer` or `NodePort`, access is available through `node IP` with its `NodePort`. +### 2. Access via In-Cluster Port-Forward (development only) -### 2. Access via Ingress +```bash +kubectl port-forward -n svc/langflow-service 8080:8080 +# open http://localhost:8080/ +``` -If Ingress is enabled, please access through the configured domain name. # Langflow Quickstart @@ -305,27 +375,40 @@ data: ``` -### 1.2 Mount ConfigMap to Container +### 1.2 Mount ConfigMap to the backend container -In Langflow configuration, mount the ConfigMap to a specified directory in the container: +Add the ConfigMap as a volume and expose the mount path through `LANGFLOW_LOAD_FLOWS_PATH`. **Remember the "array replaces defaults" rule** — the four chart-default entries (`langflow-tmp` / `app-data` / `app-db` / `app-flows`) below the custom ConfigMap entry must stay in place: ```yaml -langflow: - volumes: - - name: flows - configMap: - name: langflow-flows # ConfigMap name - volumeMounts: - - name: flows - mountPath: /app/flows # Mount path - env: - - name: LANGFLOW_LOAD_FLOWS_PATH # Set the path to load Flow files - value: /app/flows +spec: + langflow: + backend: + volumes: + # chart defaults — required, do not omit + - {name: langflow-tmp, emptyDir: {}} + - {name: app-data, emptyDir: {}} + - {name: app-db, emptyDir: {}} + - {name: app-flows, emptyDir: {}} + # additional flows source + - name: loaded-flows + configMap: {name: langflow-flows} + volumeMounts: + - {name: langflow-tmp, mountPath: /tmp} + - {name: app-data, mountPath: /app/data} + - {name: app-db, mountPath: /app/db} + - {name: app-flows, mountPath: /app/flows} + - name: loaded-flows + mountPath: /app/loaded-flows + env: + - name: LANGFLOW_LOAD_FLOWS_PATH + value: /app/loaded-flows ``` +Verified on ACP 4.3: with the above CR, restarting the backend caused Langflow to auto-import the `hello-world.json` file from the ConfigMap; `GET /api/v1/flows/` returns 34 flows (33 built-in starter projects + 1 imported). + ### 1.3 Auto Import -After configuration, Langflow will automatically scan and import JSON files in the `LANGFLOW_LOAD_FLOWS_PATH` directory on startup. +After the backend restarts, Langflow scans `LANGFLOW_LOAD_FLOWS_PATH` and auto-imports every `*.json` file in it as a Flow. Since flow ownership is tied to a user, the auto-import mode requires `LANGFLOW_AUTO_LOGIN=true` (the default) — the imported flows are attached to the built-in default user. With authentication enabled (`LANGFLOW_AUTO_LOGIN=false`), user-owned imports are not supported; use the REST API (`POST /api/v1/flows/` with a Bearer token) instead. ## 2. Using Models @@ -350,17 +433,26 @@ This approach is suitable for scenarios where: #### 2.2.1 Mount Model Files via Volume -Store model files in persistent volumes and provide them to the Langflow container through Volume mounts: +Store model files in persistent volumes and provide them to the Langflow backend container through additional volumes/volumeMounts. **Remember the [chart-defaults boilerplate](#configuration)** — the four `emptyDir` entries must be included: ```yaml -langflow: - volumes: - - name: models # Model storage volume - persistentVolumeClaim: - claimName: langflow-models-pvc - volumeMounts: # Mount model volume to specified path - - name: models - mountPath: /opt/models +spec: + langflow: + backend: + volumes: + - {name: langflow-tmp, emptyDir: {}} + - {name: app-data, emptyDir: {}} + - {name: app-db, emptyDir: {}} + - {name: app-flows, emptyDir: {}} + - name: models + persistentVolumeClaim: {claimName: langflow-models-pvc} + volumeMounts: + - {name: langflow-tmp, mountPath: /tmp} + - {name: app-data, mountPath: /app/data} + - {name: app-db, mountPath: /app/db} + - {name: app-flows, mountPath: /app/flows} + - name: models + mountPath: /opt/models ``` #### 2.2.2 Upload Models @@ -381,22 +473,33 @@ In production environments, when using custom components, additional Python pack ### 3.1 Mount Dependencies via PVC -Mount a directory using PVC to store additional Python packages. +Mount a directory using PVC to store additional Python packages. **Remember the [chart-defaults boilerplate](#configuration)**: ```yaml -langflow: - volumes: - - name: python-packages - persistentVolumeClaim: - claimName: langflow-packages-pvc # PVC name for storing additional Python packages - volumeMounts: - - name: python-packages - mountPath: /opt/python-packages # Mount path - env: - - name: PYTHONPATH # Set Python module search path - value: "/opt/python-packages" +spec: + langflow: + backend: + volumes: + - {name: langflow-tmp, emptyDir: {}} + - {name: app-data, emptyDir: {}} + - {name: app-db, emptyDir: {}} + - {name: app-flows, emptyDir: {}} + - name: python-packages + persistentVolumeClaim: {claimName: langflow-packages-pvc} + volumeMounts: + - {name: langflow-tmp, mountPath: /tmp} + - {name: app-data, mountPath: /app/data} + - {name: app-db, mountPath: /app/db} + - {name: app-flows, mountPath: /app/flows} + - name: python-packages + mountPath: /opt/python-packages + env: + - name: PYTHONPATH + value: "/opt/python-packages" ``` +Verified on ACP 4.3: pod is Ready, `env` shows `PYTHONPATH=/opt/python-packages`, mount visible at that path. + ### 3.2 Install Dependencies When installing dependency packages, use the `pip --target` parameter to install packages to the PVC-mounted directory: @@ -415,27 +518,31 @@ Flow component configurations often need different values in different environme ### 4.1 Configure Environment Variables -Add environment variables in `Custom Values` as shown in the following example: +Add environment variables under `spec.langflow.backend.env` as shown: ```yaml -langflow: - env: - - name: LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT - value: VAR1,VAR2,VAR3 # List environment variable names that Langflow can automatically load, separated by commas - - name: VAR1 # Set environment variable value, environment variable name matches Langflow global variable name - value: xxx - - name: VAR2 # Can also load value from ConfigMap - valueFrom: - configMapKeyRef: - name: langflow-configs - key: var2 - - name: VAR3 # Sensitive information should be stored using Secret - valueFrom: - secretKeyRef: - name: langflow-secrets - key: var3 +spec: + langflow: + backend: + env: + - name: LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT + value: VAR1,VAR2,VAR3 # Comma-separated list of env-var names Langflow will surface as Global Variables + - name: VAR1 + value: xxx # Plain literal + - name: VAR2 + valueFrom: + configMapKeyRef: + name: langflow-configs + key: var2 # From ConfigMap + - name: VAR3 + valueFrom: + secretKeyRef: + name: langflow-secrets + key: var3 # From Secret (recommended for sensitive values) ``` +Verified: with `LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=MY_PLAIN_VAR,MY_SECRET_KEY` on the `Langflow` custom resource, `GET /api/v1/variables/` returns both entries with `type: Credential`, ready to be referenced from flow components. + ### 4.2 Use Global Variables in Flows In Langflow's flow editor: @@ -454,60 +561,75 @@ To improve performance, security, and stability in production environments, the Langflow collects usage data by default. In production environments, this feature can be disabled to protect privacy and reduce network requests: ```yaml -langflow: - env: - - name: DO_NOT_TRACK # Disable usage tracking - value: "true" +spec: + langflow: + backend: + env: + - name: DO_NOT_TRACK + value: "true" ``` ### 5.2 Disable Transaction Logs -During each request processing, Langflow records the input, output, and execution logs of each component to the database, which is the information shown in the Langflow IDE's Logs panel. -In production environments, this logging can be disabled to improve performance and reduce database pressure. +Langflow records the input, output, and execution log of each component to the database (visible in the IDE's Logs panel). Disabling reduces database write pressure: ```yaml -langflow: - env: - - name: LANGFLOW_TRANSACTIONS_STORAGE_ENABLED - value: "false" # Disable transaction logs +spec: + langflow: + backend: + env: + - name: LANGFLOW_TRANSACTIONS_STORAGE_ENABLED + value: "false" ``` ### 5.3 Set Worker Process Count ```yaml -langflow: - numWorkers: 1 # Set number of worker processes +spec: + langflow: + backend: + numWorkers: 1 # gunicorn worker count (default: 1) ``` ### 5.4 Configure Resource Limits -It is recommended to configure appropriate resource limits for the Langflow container. The following YAML is only an example; adjust the values according to actual requirements: +It is recommended to configure appropriate resource limits for the backend and frontend containers separately. Sample values (adjust to your workload): ```yaml -langflow: - resources: - requests: - cpu: "2" - memory: "4Gi" - limits: - cpu: "4" - memory: "8Gi" +spec: + langflow: + backend: + resources: + requests: {cpu: "2", memory: "4Gi"} + limits: {cpu: "4", memory: "8Gi"} + frontend: + resources: + requests: {cpu: "0.3", memory: "512Mi"} ``` -### 5.5 Set API Keys +### 5.5 Use API Keys -1. Go to the **Settings** page -2. In the **Langflow API Keys** section, add API keys -3. When making API requests, add the `x-api-key: ` header; otherwise, a 401 error (unauthorized request) will be returned +Langflow supports `x-api-key`-based authentication for REST requests. Two ways to create a key: -### 5.6 Disable UI +1. **Via the IDE (Settings → Langflow API Keys)**: click "Add New" and give the key a name; Langflow returns the key value once (store it immediately). +2. **Via REST**: `POST /api/v1/api_key/` with a Bearer token in `Authorization`: + ```bash + curl -X POST http:///api/v1/api_key/ \ + -H "Authorization: Bearer " \ + -H "Content-Type: application/json" \ + -d '{"name":"my-key"}' + ``` + The response body contains `api_key` — record it. -Runtime mode allows Langflow to run without a browser interface, suitable for API service scenarios in production environments. +Use the key by sending `x-api-key: ` on subsequent requests: +- Valid key → `200` +- Missing / wrong key → `403` -```yaml -langflow: - backendOnly: true # Enable backend-only mode -``` +Verified with the e2e smoke H probe on 4.3-x86: creating a key + hitting `/api/v1/all` with the valid key returns 200 with the full component catalog; hitting the same endpoint with a wrong key returns 403. + +### 5.6 Disable UI + +See [Configure Runtime Mode](#6-configure-runtime-mode-backend-only) — set both `backend.backendOnly=true` and `frontend.enabled=false` to actually drop the frontend Deployment. ### 5.7 Reference Official Documentation diff --git a/docs/zh/solutions/How_to_install_and_use_Langflow.md b/docs/zh/solutions/How_to_install_and_use_Langflow.md deleted file mode 100644 index 0dcb03d9a..000000000 --- a/docs/zh/solutions/How_to_install_and_use_Langflow.md +++ /dev/null @@ -1,529 +0,0 @@ ---- -products: - - Alauda AI -kind: - - Solution -ProductsVersion: - - 4.x -id: KB1762309013-4C37 -sourceSHA: de62ac771d9db6c326ce6a20a4713807868944f71427b629c6aa91caeef42adb ---- - -# Langflow - -## 概述 - -Langflow 是一个开源低代码工具,用于可视化构建和部署 AI 代理和工作流。它提供了一个拖放编辑器,可以快速创建、测试和迭代 AI 应用程序。Langflow 基于 Python 构建,包含一个 FastAPI 后端和一个基于 React 的可视化编辑器。它默认支持 SQLite,并建议在生产环境中使用 PostgreSQL。 - -它包含以下主要组件: - -- **前端界面**:基于 React 的可视化编辑器,支持拖放流程构建和实时测试 -- **后端服务**:基于 FastAPI 的网络服务,提供 REST API 和 MCP(模型上下文协议)支持 -- **数据库**:支持 SQLite(默认)和 PostgreSQL(推荐用于生产) - -## 核心概念 - -Langflow 是围绕几个核心概念构建的:**流程**(组织 AI 逻辑的可视化工作流)、**组件**(可重用的功能单元)、**代理**(具有工具调用和推理能力的智能代理)和 **API/MCP** 集成(支持 REST API 和模型上下文协议)。 - -Langflow 提供了一个拖放可视化界面,用于构建具有实时测试功能的 AI 应用程序,并拥有丰富的模板库。它支持多个 LLM 提供商、嵌入模型和向量数据库,能够实现灵活的多模型配置。该平台提供开发的 IDE 模式和生产部署的运行时模式,适合实验和企业使用。 - -有关核心概念、功能和使用的详细信息,请参阅 [官方文档](https://docs.langflow.org/)。 - -## 文档和参考 - -- **官方文档**: -- **GitHub 仓库**: - -# Langflow 部署指南 - -本节提供有关如何将 Langflow 部署到 Kubernetes 集群的详细说明和常见配置参数。 - -## 发布 - -下载 Langflow 安装文件:`langflow.ALL.v1.6.4-1.tgz` - -使用 violet 命令发布到平台仓库: - -```bash -violet push --platform-address=platform-access-address --platform-username=platform-admin --platform-password=platform-admin-password langflow.ALL.v1.6.4-1.tgz -``` - -## 部署 - -### 准备存储 - -Langflow 支持两种数据库模式: - -- **SQLite(默认)**:用于开发和测试,数据存储在持久卷中 -- **PostgreSQL(推荐)**:用于生产环境,提供更好的性能和可扩展性 - -集群需要预先安装 CSI 或预先准备 `PersistentVolume`。 - -### 准备数据库 - -#### 使用 SQLite(默认) - -SQLite 是 Langflow 的默认数据库,适合开发和测试环境: - -- 数据存储在持久卷中 -- 配置简单,无需额外设置 -- 支持单实例部署 - -#### 使用 PostgreSQL(推荐) - -强烈建议在生产环境中使用 PostgreSQL,以获得更好的性能和可扩展性: - -可以使用 `Data Services` 提供的 `PostgreSQL operator` 创建 `PostgreSQL 集群`。 - -检查 `Data Services` 中 `PostgreSQL` 实例详细信息中的访问地址和密码。 - -**注意**: - -- 推荐使用 PostgreSQL 版本 12 或更高 -- 需要创建单独的数据库和用户 -- 确保网络连接 - -### 创建应用程序 - -1. 转到 `Alauda Container Platform` 视图,选择将要部署 Langflow 的命名空间。 - -2. 在左侧导航中选择 `Applications` / `Applications`,然后点击右侧页面的 `Create` 按钮。 - -3. 在弹出对话框中选择 `Create from Catalog`,然后页面将跳转到 `Catalog` 视图。 - -4. 找到 `3rdparty/chart-langflow` 并点击 `Create` 创建此应用程序。 - -5. 在 `Catalog` / `Create langflow` 表单中,填写 `Name`(推荐为 `langflow`)和 `Values` 中的 `Custom` 配置,然后点击 `Create` 按钮完成创建。`Custom` 内容将在下面描述。创建后也可以通过 `Update` 应用程序方法进行修改。 - -## 配置 - -用户可以修改 `Application` 的 `Custom Values` 以调整配置。主要关注的配置如下: - -### 1. 配置存储 - -#### 1.1 配置 SQLite 存储(默认) - -可以通过添加以下配置来指定存储类和大小: - -```yaml -langflow: - sqlite: - volume: - storageClassName: storage-class-name # 替换为实际的存储类名称 - size: 1Gi # 替换为实际所需空间大小 -``` - -**注意**:使用 SQLite 时,仅支持单实例部署(replicaCount = 1)。 - -### 2. 配置数据库 - -#### 2.1 启用 PostgreSQL - -可以通过设置以下字段配置 PostgreSQL 访问信息: - -```yaml -langflow: - externalDatabase: - enabled: true # 启用外部数据库 - driver: - value: "postgresql" - host: - value: postgres-host # PostgreSQL 访问地址 - port: - value: "5432" # PostgreSQL 访问端口,默认:5432 - database: - value: langflow # 数据库名称,注意:数据库将自动创建 - user: - value: langflow # 数据库用户名 - password: - valueFrom: - secretKeyRef: - name: postgres-secret # 存储数据库访问密码的秘密名称 - key: password # 存储数据库访问密码的秘密键 -``` - -**注意**:由于临时存储限制,当前版本暂时不支持多实例部署。即使配置了 PostgreSQL 数据库,仅支持单实例部署(replicaCount = 1)。 - -### 3. 配置访问方式 - -默认情况下,使用 `LoadBalancer` 提供访问地址。 - -#### 3.1 修改服务类型 - -可以通过设置以下字段修改 `Service` 类型: - -```yaml -langflow: - service: - type: LoadBalancer # 可以更改为 NodePort 或 ClusterIP - port: 7860 # 服务端口 -``` - -#### 3.2 启用 Ingress - -可以通过设置以下字段配置 Ingress。启用 Ingress 后,服务类型通常更改为 ClusterIP: - -```yaml -ingress: - enabled: true # 启用 Ingress 功能 - hosts: - - host: langflow.example.com # 访问域名(必须是 DNS 名称,而不是 IP 地址) - paths: - - path: / - tls: - - secretName: langflow-tls # 存储 TLS 证书的秘密名称 - hosts: - - langflow.example.com -``` - -### 4. 配置身份验证和用户管理(可选) - -#### 4.1 启用用户身份验证 - -可以通过设置以下字段启用用户身份验证: - -```yaml -langflow: - auth: - enabled: true # 启用身份验证 - superuser: - username: langflow # 超级用户名称 - password: "" # 超级用户密码,未设置时自动生成 - secretKey: "" # 秘密密钥,未设置时自动生成 - newUserActive: false # 新用户是否需要激活 - enableSuperuserCLI: false # 是否启用 CLI 超级用户 - accessTokenExpireSeconds: 3600 # 访问令牌过期时间(秒) - refreshTokenExpireSeconds: 604800 # 刷新令牌过期时间(秒) -``` - -启用身份验证后,默认情况下: - -- 需要登录才能访问 -- 可以配置超级用户 -- 新用户只能通过超级用户在 `/admin` 页面添加(不支持自我注册) -- 新用户账户激活:如果 `newUserActive=true`,新用户账户将自动激活;如果 `newUserActive=false`(默认),超级用户需要手动激活 - -### 5. 配置 OAuth2 代理(可选) - -可以通过设置以下字段配置 OAuth2 代理,以提供单点登录功能: - -```yaml -oauth2_proxy: - enabled: true # 启用 OAuth2 代理 - oidcIssuer: "https://x.x.x.com/dex" # OIDC 发行者地址 - oidcClientID: "your-client-id" # OIDC 客户端 ID - oidcClientSecret: "your-client-secret" # OIDC 客户端密钥(建议使用 Secret) -``` - -要将 `Alauda Container Platform` 配置为 OIDC 提供者,请按如下方式配置: - -- `oauth2_proxy.oidcIssuer` 是平台访问地址加上 `/dex` -- `oauth2_proxy.oidcClientID` 固定为 `langflow` -- `oauth2_proxy.oidcClientSecret` 固定为 `ZXhhbXBsZS1hcHAtc2VjcmV0` - -还需要在 global 集群中创建 OAuth2Client 资源以配置 Langflow 的客户端信息: - -```yaml -apiVersion: dex.coreos.com/v1 -kind: OAuth2Client -metadata: - name: nrqw4z3gnrxxps7sttsiiirdeu - namespace: cpaas-system -id: langflow # 与 values 中的 oauth2_proxy.oidcClientID 一致 -name: Langflow -secret: ZXhhbXBsZS1hcHAtc2VjcmV0 # 与 values 中的 oauth2_proxy.oidcClientSecret 一致 -redirectURIs: -- http://xxx.xxx.xxxx.xxx:xxxxx/* # OAuth2-Proxy 访问地址,获取方法如下 - # 如果部署多个 Langflow 实例,请在此处添加多个访问地址 -``` - -**注意**:OAuth2 代理访问地址可以从 `-oauth2-proxy` 服务中获取,根据服务类型使用适当的访问方法。 - -启用 OAuth2 代理后,建议: - -- 将 `langflow.service.type` 设置为 `ClusterIP`,仅允许在集群内访问。用户需要通过 OAuth2 代理地址访问 Langflow。 -- 将 `langflow.auth.enabled` 设置为 `false`。使用 OAuth2 代理处理登录身份验证。 - -用户可以通过访问 `/oauth2/sign_out` 登出。 - -### 6. 配置运行时模式(仅后端) - -运行时模式是推荐的生产环境部署方法,仅部署 Langflow 后端 API 服务,而不提供可视化界面。 - -#### 6.1 启用运行时模式 - -可以通过设置以下字段启用运行时模式(仅后端): - -```yaml -langflow: - backendOnly: true # 启用仅后端模式 - env: - - name: LANGFLOW_LOAD_FLOWS_PATH # 设置加载 Flows 的路径 - value: "/app/flows" - volumes: - - name: flows # 通过卷加载 Flows 内容 - persistentVolumeClaim: # 从 PVC 或其他卷 - claimName: langflow-flows-pvc - volumeMounts: # 将卷挂载到指定路径 - - name: flows - mountPath: /app/flows -``` - -启用 `LANGFLOW_LOAD_FLOWS_PATH` 时,必须禁用身份验证,即 `langflow.auth.enabled` 必须设置为 `false`。 - -## 访问地址 - -### 1. 通过服务访问 - -`Langflow` 通过 `Service` 提供外部访问。检查其 `Service` 以获取访问地址。 - -- 如果未启用 OAuth2 代理,服务名称为:`` -- 如果启用 OAuth2 代理,服务名称为:`-oauth2-proxy` - -如果 `Service` 类型为 `LoadBalancer`,并且环境中的负载均衡控制器已分配访问地址,请通过该地址访问。 - -如果 `Service` 类型为 `LoadBalancer` 或 `NodePort`,可以通过 `node IP` 及其 `NodePort` 进行访问。 - -### 2. 通过 Ingress 访问 - -如果启用了 Ingress,请通过配置的域名访问。 - -# Langflow 快速入门 - -有关快速入门指南,请参阅官方文档: - -# 生产环境建议 - -本节提供在生产环境中使用 Langflow 的实用建议和优化配置。 - -## 1. 通过 ConfigMap 导入现有流程 - -在生产环境中,可以通过 Kubernetes ConfigMap 将现有流程文件导入 Langflow。 - -### 1.1 创建包含流程 JSON 的 ConfigMap - -首先,创建一个包含流程 JSON 文件的 ConfigMap: - -```yaml -apiVersion: v1 -kind: ConfigMap -metadata: - name: langflow-flows - namespace: -data: - project1.json: | - -``` - -### 1.2 将 ConfigMap 挂载到容器 - -在 Langflow 配置中,将 ConfigMap 挂载到容器中的指定目录: - -```yaml -langflow: - volumes: - - name: flows - configMap: - name: langflow-flows # ConfigMap 名称 - volumeMounts: - - name: flows - mountPath: /app/flows # 挂载路径 - env: - - name: LANGFLOW_LOAD_FLOWS_PATH # 设置加载流程文件的路径 - value: /app/flows -``` - -### 1.3 自动导入 - -配置完成后,Langflow 将在启动时自动扫描并导入 `LANGFLOW_LOAD_FLOWS_PATH` 目录中的 JSON 文件。 - -## 2. 使用模型 - -在生产环境中,可以通过两种方式加载和使用模型:通过 API 调用远程模型或通过卷挂载加载本地模型。根据具体需求选择适当的方法。 - -### 2.1 调用远程模型 - -这种方法适用于以下场景: - -- 模型有显著的资源需求 -- 模型需要在多个服务之间共享 -- 需要独立的扩展和资源管理 -- 模型版本管理和更新需要单独处理 - -远程模型可以是自部署的模型服务或供应商提供的第三方模型服务。要在 Langflow 中使用远程模型,在流程编辑器中,使用基于 API 的模型组件(例如 OpenAI、Custom API 等)通过配置 API 基础 URL 和身份验证凭据连接到模型服务端点。 - -### 2.2 加载本地模型 - -这种方法适用于以下场景: - -- 模型的资源开销较低(例如,嵌入模型) -- 模型大小和资源消耗在 Langflow 容器内可控 -- 需要直接文件访问模型 - -#### 2.2.1 通过卷挂载模型文件 - -将模型文件存储在持久卷中,并通过卷挂载将其提供给 Langflow 容器: - -```yaml -langflow: - volumes: - - name: models # 模型存储卷 - persistentVolumeClaim: - claimName: langflow-models-pvc - volumeMounts: # 将模型卷挂载到指定路径 - - name: models - mountPath: /opt/models -``` - -#### 2.2.2 上传模型 - -用户可以使用 `kubectl cp` 命令将模型上传到 Langflow 容器,如下所示: - -```bash -kubectl cp -n :/opt/models -``` - -#### 2.2.3 在组件中配置本地模型 - -在 Langflow 的流程编辑器中,使用相应的模型组件时,可以将本地模型访问路径配置为 `/opt/models`。 - -## 3. 添加额外的 Python 依赖 - -在生产环境中,当使用自定义组件时,可能需要安装额外的 Python 包。可以按如下方式进行: - -### 3.1 通过 PVC 挂载依赖 - -使用 PVC 挂载一个目录以存储额外的 Python 包。 - -```yaml -langflow: - volumes: - - name: python-packages - persistentVolumeClaim: - claimName: langflow-packages-pvc # 存储额外 Python 包的 PVC 名称 - volumeMounts: - - name: python-packages - mountPath: /opt/python-packages # 挂载路径 - env: - - name: PYTHONPATH # 设置 Python 模块搜索路径 - value: "/opt/python-packages" -``` - -### 3.2 安装依赖 - -安装依赖包时,使用 `pip --target` 参数将包安装到 PVC 挂载的目录: - -```bash -# 在容器中执行,将包安装到 PVC 挂载的目录 -pip install --target /opt/python-packages package-name - -# 或从 requirements.txt 安装 -pip install --target /opt/python-packages -r requirements.txt -``` - -## 4. 通过环境变量传递全局变量 - -流程组件配置通常需要在不同环境中使用不同的值。Langflow 的全局变量功能允许将这些特定于环境的值与流程定义分开。全局变量的值可以从环境变量加载。 - -### 4.1 配置环境变量 - -在 `Custom Values` 中添加环境变量,如下所示: - -```yaml -langflow: - env: - - name: LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT - value: VAR1,VAR2,VAR3 # 列出 Langflow 可以自动加载的环境变量名称,以逗号分隔 - - name: VAR1 # 设置环境变量值,环境变量名称与 Langflow 全局变量名称匹配 - value: xxx - - name: VAR2 # 也可以从 ConfigMap 加载值 - valueFrom: - configMapKeyRef: - name: langflow-configs - key: var2 - - name: VAR3 # 敏感信息应使用 Secret 存储 - valueFrom: - secretKeyRef: - name: langflow-secrets - key: var3 -``` - -### 4.2 在流程中使用全局变量 - -在 Langflow 的流程编辑器中: - -1. 转到 **设置** 页面 -2. 在 **全局变量** 部分,添加全局变量并设置其值 -3. 在组件配置中引用这些全局变量 -4. 导出流程时,**必须**选择“与我的 API 密钥一起保存”,否则全局变量配置可能不会包含在导出的 JSON 文件中 - -## 5. 优化建议 - -为提高生产环境中的性能、安全性和稳定性,建议进行以下优化配置: - -### 5.1 禁用使用跟踪 - -Langflow 默认收集使用数据。在生产环境中,可以禁用此功能以保护隐私并减少网络请求: - -```yaml -langflow: - env: - - name: DO_NOT_TRACK # 禁用使用跟踪 - value: "true" -``` - -### 5.2 禁用事务日志 - -在每次请求处理期间,Langflow 会将每个组件的输入、输出和执行日志记录到数据库中,这些信息显示在 Langflow IDE 的日志面板中。 -在生产环境中,可以禁用此日志记录以提高性能并减少数据库压力。 - -```yaml -langflow: - env: - - name: LANGFLOW_TRANSACTIONS_STORAGE_ENABLED - value: "false" # 禁用事务日志 -``` - -### 5.3 设置工作进程数量 - -```yaml -langflow: - numWorkers: 1 # 设置工作进程数量 -``` - -### 5.4 配置资源限制 - -建议为 Langflow 容器配置适当的资源限制。以下 YAML 仅为示例;根据实际需求调整值: - -```yaml -langflow: - resources: - requests: - cpu: "2" - memory: "4Gi" - limits: - cpu: "4" - memory: "8Gi" -``` - -### 5.5 设置 API 密钥 - -1. 转到 **设置** 页面 -2. 在 **Langflow API 密钥** 部分,添加 API 密钥 -3. 在进行 API 请求时,添加 `x-api-key: ` 头;否则将返回 401 错误(未经授权的请求) - -### 5.6 禁用 UI - -运行时模式允许 Langflow 在没有浏览器界面的情况下运行,适合生产环境中的 API 服务场景。 - -```yaml -langflow: - backendOnly: true # 启用仅后端模式 -``` - -### 5.7 参考官方文档 - -有关发布流程和生产最佳实践的更详细信息,请参阅官方 Langflow 文档: - -- **发布概念**: -- **生产最佳实践**: