docs: Adding Best practices for Deploying and Running Langflow in production (#7311)

* Adding Best practices on running Langflow in production

* combine-content

* combine-more-content-and-sidebars

* sidebars

* docs: add deployment guide for Langflow development environment on Kubernetes

- Introduced a new page for deploying the Langflow IDE in a development environment on Kubernetes.
- Updated sidebar to reflect the new deployment guide.
- Adjusted existing documentation links to point to the new development deployment page.

* combine-more-content-and-sidebars

* combine-more-content-and-sidebars

* Enhance docs: Dark mode messaging, fix link, update title, reorder pages

- Enhanced the messages for Dark Mode support
- Fixed broken link in Deployment Docker pointing to Deployment Kubernetes
- Updated title to 'Langflow Architecture and Best Practices' from 'Langflow Best Practices'
- Changed ordering of pages in Deployment Kubernetes section

* Restore missing content

* Cleaning stale changes in sidebars

* Update docs/docs/Deployment/deployment-prod-best-practices.md

Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-prod-best-practices.md

Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-prod-best-practices.md

Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-prod-best-practices.md

Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>

* Update docs/docs/Develop/develop-application.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-prod-best-practices.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-prod-best-practices.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-prod-best-practices.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-prod-best-practices.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-kubernetes-dev.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-kubernetes-dev.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-kubernetes-dev.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-kubernetes-dev.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-docker.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-kubernetes-prod.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-kubernetes-prod.md

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

* Update docs/docs/Deployment/deployment-prod-best-practices.md

Co-authored-by: Eric Schneider <37347760+eric-schneider@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>

---------

Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>
Co-authored-by: KimberlyFields <46325568+KimberlyFields@users.noreply.github.com>
Co-authored-by: Eric Schneider <37347760+eric-schneider@users.noreply.github.com>
This commit is contained in:
nidhimishra-datastax 2025-05-06 05:49:32 +08:00 • committed by GitHub
commit 102946be72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 260 additions and 194 deletions

View file

@ -128,7 +128,7 @@ docker build -t myuser/langflow-hello-world:1.0.0 .
docker push myuser/langflow-hello-world:1.0.0
```
To deploy the image with Helm, see [Langflow runtime deployment](/deployment-kubernetes#deploy-the-langflow-runtime).
To deploy the image with Helm, see [Deploy the Langflow production environment on Kubernetes](/deployment-kubernetes-prod).
## Customize the Langflow Docker image with your own code

View file

@ -0,0 +1,160 @@
---
title: Deploy the Langflow development environment on Kubernetes
slug: /deployment-kubernetes-dev
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
The [Langflow Integrated Development Environment (IDE)](https://github.com/langflow-ai/langflow-helm-charts/tree/main/charts/langflow-ide) Helm chart is designed to provide a complete environment for developers to create, test, and debug their flows. It includes both the API and the UI.
### Prerequisites
- A [Kubernetes](https://kubernetes.io/docs/setup/) cluster
- [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
- [Helm](https://helm.sh/docs/intro/install/)
### Prepare a Kubernetes cluster
This example uses [Minikube](https://minikube.sigs.k8s.io/docs/start/), but you can use any Kubernetes cluster.
1. Create a Kubernetes cluster on Minikube.
```shell
minikube start
```
2. Set `kubectl` to use Minikube.
```shell
kubectl config use-context minikube
```
### Install the Langflow IDE Helm chart
1. Add the repository to Helm and update it.
```shell
helm repo add langflow https://langflow-ai.github.io/langflow-helm-charts
helm repo update
```
2. Install Langflow with the default options in the `langflow` namespace.
```shell
helm install langflow-ide langflow/langflow-ide -n langflow --create-namespace
```
3. Check the status of the pods.
```shell
kubectl get pods -n langflow
```
### Access the Langflow IDE
Enable local port forwarding to access Langflow from your local machine.
1. To make the Langflow API accessible from your local machine at port 7860:
```shell
kubectl port-forward -n langflow svc/langflow-service-backend 7860:7860
```
2. To make the Langflow UI accessible from your local machine at port 8080:
```shell
kubectl port-forward -n langflow svc/langflow-service 8080:8080
```
Now you can do the following:
- Access the Langflow API at `http://localhost:7860`.
- Access the Langflow UI at `http://localhost:8080`.
### Configure the Langflow version
Langflow is deployed with the `latest` version by default.
To specify a different Langflow version, set the `langflow.backend.image.tag` and `langflow.frontend.image.tag` values in the [values.yaml](https://github.com/langflow-ai/langflow-helm-charts/blob/main/charts/langflow-ide/values.yaml) file.
```yaml
langflow:
backend:
image:
tag: "1.0.0a59"
frontend:
image:
tag: "1.0.0a59"
```
### Configure external storage
By default, the chart deploys a SQLite database stored in a local persistent disk. If you want to use an external PostgreSQL database, you can configure it in two ways:
* Use the built-in PostgreSQL chart:
```yaml
postgresql:
enabled: true
auth:
username: "langflow"
password: "langflow-postgres"
database: "langflow-db"
```
* Use an external database:
```yaml
postgresql:
enabled: false
langflow:
backend:
externalDatabase:
enabled: true
driver:
value: "postgresql"
port:
value: "5432"
user:
value: "langflow"
password:
valueFrom:
secretKeyRef:
key: "password"
name: "your-secret-name"
database:
value: "langflow-db"
sqlite:
enabled: false
```
### Configure scaling
Scale the number of replicas and resources for both frontend and backend services:
```yaml
langflow:
backend:
replicaCount: 1
resources:
requests:
cpu: 0.5
memory: 1Gi
# limits:
# cpu: 0.5
# memory: 1Gi
frontend:
enabled: true
replicaCount: 1
resources:
requests:
cpu: 0.3
memory: 512Mi
# limits:
# cpu: 0.3
# memory: 512Mi
```
:::note
If your flow relies on a shared state, such as built-in chat memory, you need to set up a shared database when scaling horizontally.
:::
For more examples of `langflow-ide` deployment, see the [Langflow Helm Charts repository](https://github.com/langflow-ai/langflow-helm-charts/tree/main/examples/langflow-ide).

View file

@ -0,0 +1,191 @@
---
title: Deploy the Langflow production environment on Kubernetes
slug: /deployment-kubernetes-prod
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
The [Langflow Runtime](https://github.com/langflow-ai/langflow-helm-charts/blob/main/charts/langflow-runtime) chart is tailored for deploying applications in a production environment. It is focused on stability, performance, isolation, and security to ensure that applications run reliably and efficiently.
:::important
By default, the [Langflow runtime Helm chart](https://github.com/langflow-ai/langflow-helm-charts/blob/main/charts/langflow-runtime/values.yaml#L46) enables `readOnlyRootFilesystem: true` as a security best practice. This setting prevents modifications to the container's root filesystem at runtime, which is a recommended security measure in production environments.
Disabling `readOnlyRootFilesystem` reduces the security of your deployment. Only disable this setting if you understand the security implications and have implemented other security measures.
For more information, see the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/).
:::
### Prerequisites
- A [Kubernetes](https://kubernetes.io/docs/setup/) server
- [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
- [Helm](https://helm.sh/docs/intro/install/)
### Install the Langflow runtime Helm chart
1. Add the repository to Helm.
```shell
helm repo add langflow https://langflow-ai.github.io/langflow-helm-charts
helm repo update
```
2. Install the Langflow app with the default options in the `langflow` namespace.
If you have a created a [custom image with packaged flows](/deployment-docker#package-your-flow-as-a-docker-image), you can deploy Langflow by overriding the default [values.yaml](https://github.com/langflow-ai/langflow-helm-charts/blob/main/charts/langflow-runtime/values.yaml) file with the `--set` flag.
* Use a custom image with bundled flows:
```shell
helm install my-langflow-app langflow/langflow-runtime -n langflow --create-namespace --set image.repository=myuser/langflow-hello-world --set image.tag=1.0.0
```
* Alternatively, install the chart and download the flows from a URL with the `--set` flag:
```shell
helm install my-langflow-app-with-flow langflow/langflow-runtime \
-n langflow \
--create-namespace \
--set 'downloadFlows.flows[0].url=https://raw.githubusercontent.com/langflow-ai/langflow/dev/tests/data/basic_example.json'
```
:::important
You may need to escape the square brackets in this command if you are using a shell that requires it:
```shell
helm install my-langflow-app-with-flow langflow/langflow-runtime \
-n langflow \
--create-namespace \
--set 'downloadFlows.flows\[0\].url=https://raw.githubusercontent.com/langflow-ai/langflow/dev/tests/data/basic_example.json'
```
:::
3. Check the status of the pods.
```shell
kubectl get pods -n langflow
```
### Access the Langflow runtime
1. Get your service name.
```shell
kubectl get svc -n langflow
```
The service name is your release name followed by `-langflow-runtime`. For example, if you used `helm install my-langflow-app-with-flow` the service name is `my-langflow-app-with-flow-langflow-runtime`.
2. Enable port forwarding to access Langflow from your local machine:
```shell
kubectl port-forward -n langflow svc/my-langflow-app-with-flow-langflow-runtime 7860:7860
```
3. Confirm you can access the API at `http://localhost:7860/api/v1/flows/` and view a list of flows.
```shell
curl -v http://localhost:7860/api/v1/flows/
```
4. Execute the packaged flow.
The following command gets the first flow ID from the flows list and runs the flow.
```shell
# Get flow ID
id=$(curl -s "http://localhost:7860/api/v1/flows/" | jq -r '.[0].id')
# Run flow
curl -X POST \
"http://localhost:7860/api/v1/run/$id?stream=false" \
-H 'Content-Type: application/json' \
-d '{
"input_value": "Hello!",
"output_type": "chat",
"input_type": "chat"
}'
```
### Configure secrets
To inject secrets and Langflow global variables, use the `secrets` and `env` sections in the [values.yaml](https://github.com/langflow-ai/langflow-helm-charts/blob/main/charts/langflow-runtime/values.yaml) file.
For example, the [example flow JSON](https://raw.githubusercontent.com/langflow-ai/langflow-helm-charts/refs/heads/main/examples/flows/basic-prompting-hello-world.json) uses a global variable that is a secret. When you export the flow as JSON, it's recommended to not include the secret.
Instead, when importing the flow in the Langflow runtime, you can set the global variable in one of the following ways:
<Tabs>
<TabItem value="values" label="Using values.yaml">
```yaml
env:
- name: openai_key_var
valueFrom:
secretKeyRef:
name: openai-key
key: openai-key
```
Or directly in the values file (not recommended for secret values):
```yaml
env:
- name: openai_key_var
value: "sk-...."
```
</TabItem>
<TabItem value="helm" label="Using Helm Commands">
1. Create the secret:
```shell
kubectl create secret generic openai-credentials \
--namespace langflow \
--from-literal=OPENAI_API_KEY=sk...
```
2. Verify the secret exists. The result is encrypted.
```shell
kubectl get secrets -n langflow openai-credentials
```
3. Upgrade the Helm release to use the secret.
```shell
helm upgrade my-langflow-app-image langflow/langflow-runtime -n langflow \
--reuse-values \
--set "extraEnv[0].name=OPENAI_API_KEY" \
--set "extraEnv[0].valueFrom.secretKeyRef.name=openai-credentials" \
--set "extraEnv[0].valueFrom.secretKeyRef.key=OPENAI_API_KEY"
```
</TabItem>
</Tabs>
### Configure the log level
Set the log level and other Langflow configurations in the [values.yaml](https://github.com/langflow-ai/langflow-helm-charts/blob/main/charts/langflow-runtime/values.yaml) file.
```yaml
env:
- name: LANGFLOW_LOG_LEVEL
value: "INFO"
```
### Configure scaling
To scale the number of replicas for the Langflow appplication, change the `replicaCount` value in the [values.yaml](https://github.com/langflow-ai/langflow-helm-charts/blob/main/charts/langflow-runtime/values.yaml) file.
```yaml
replicaCount: 3
```
To scale the application vertically by increasing the resources for the pods, change the `resources` values in the [values.yaml](https://github.com/langflow-ai/langflow-helm-charts/blob/main/charts/langflow-runtime/values.yaml) file.
```yaml
resources:
requests:
memory: "2Gi"
cpu: "1000m"
```
For more information about deploying Langflow on AWS EKS, Google GKE, or Azure AKS, see the [Langflow Helm Charts repository](https://github.com/langflow-ai/langflow-helm-charts).

View file

@ -10,15 +10,18 @@ You have a flow, and want to share it with the world in a production environment
This page outlines the journey from locally-run flow to a cloud-hosted production server.
More specific instructions are available in the [Docker](/deployment-docker) and [Kubernetes](/deployment-kubernetes) pages.
More specific instructions are available in the [Docker](/deployment-docker) and [Kubernetes](/deployment-kubernetes-dev) pages.
## Langflow deployment architecture
Langflow can be deployed as an [IDE](https://github.com/langflow-ai/langflow-helm-charts/tree/main/charts/langflow-ide) or as a [runtime](https://github.com/langflow-ai/langflow-helm-charts/tree/main/charts/langflow-runtime).
Langflow can be deployed in two distinct environments:
The **IDE** includes the frontend for visual development of your flow. The default [docker-compose.yml](https://github.com/langflow-ai/langflow/blob/main/docker_example/docker-compose.yml) file hosted in the Langflow repository builds the Langflow IDE image. To deploy the Langflow IDE, see [Docker](/deployment-docker).
* [Langflow IDE](/deployment-kubernetes-dev) - A development environment for creating and testing flows.
* [Langflow runtime](/deployment-kubernetes-prod) - A production environment for hosting and serving flows.
The **runtime** is a headless or backend-only mode. The server exposes your flow as an endpoint, and runs only the processes necessary to serve your flow, with PostgreSQL as the database for improved scalability. Use the Langflow **runtime** to deploy your flows, because you don't require the frontend for visual development.
The **Langflow IDE** includes the frontend for visual development of your flow. The default [docker-compose.yml](https://github.com/langflow-ai/langflow/blob/main/docker_example/docker-compose.yml) file hosted in the Langflow repository builds the Langflow IDE image. The Langflow IDE can be deployed on [Docker](/deployment-docker) or [Kubernetes](/deployment-kubernetes-dev).
The **Langflow runtime** is a headless or backend-only mode. The server exposes your flow as an endpoint, and runs only the processes necessary to serve your flow, with PostgreSQL as the database for improved scalability. Use the Langflow **runtime** to deploy your flows if you don't require the frontend for visual development. The Langflow runtime can be deployed on [Docker](/deployment-docker) or [Kubernetes](/deployment-kubernetes-prod).
:::tip
You can start Langflow in headless mode with the [LANGFLOW_BACKEND_ONLY](/environment-variables#LANGFLOW_BACKEND_ONLY) environment variable.
@ -36,7 +39,10 @@ For more on building the Langflow docker image and pushing it to Docker Hub, see
After your flow is packaged as a Docker image and available on Docker Hub, deploy your application by overriding the values in the [langflow-runtime](https://github.com/langflow-ai/langflow-helm-charts/blob/main/charts/langflow-runtime/Chart.yaml) Helm chart.
For more information, see [Deploy Langflow on Kubernetes](/deployment-kubernetes).
For more information, see [Deploy the Langflow development environment on Kubernetes](/deployment-kubernetes-dev).

View file

@ -0,0 +1,55 @@
---
title: Langflow architecture and best practices on Kubernetes
slug: /deployment-prod-best-practices
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
While Langflow offers flexible deployment options, deploying on a Kubernetes cluster is highly recommended for production environments.
Deploying on Kubernetes offers the following advantages:
* **Scalability**: Kubernetes allows you to scale the Langflow service to meet the demands of your workload.
* **Availability and resilience**: Kubernetes provides built-in resilience features, such as automatic failover and self-healing, to ensure that the Langflow service is always available.
* **Security**: Kubernetes provides security features, such as role-based access control and network isolation, to protect the Langflow service and its data.
* **Portability**: Kubernetes is a portable platform, which means that you can deploy the Langflow service to any Kubernetes cluster, on-premises or in the cloud.
Langflow can be deployed on cloud deployments like **AWS EKS, Google GKE, or Azure AKS**. For more information about deploying Langflow on AWS EKS, Google GKE, or Azure AKS, see the [Langflow Helm charts repository](https://github.com/langflow-ai/langflow-helm-charts).
## Langflow deployment
A typical Langflow deployment includes:
* **Langflow API and UI** – The Langflow service is the core component of the Langflow platform. It provides a RESTful API for executing flows.
* **Kubernetes cluster** – The Kubernetes cluster provides a platform for deploying and managing the Langflow service and its supporting components.
* **Persistent storage** – Persistent storage is used to store the Langflow service's data, such as models and training data.
* **Ingress controller** – The ingress controller provides a single entry point for traffic to the Langflow service.
* **Load balancer** – Balances traffic across multiple Langflow replicas.
* **Vector database** – If you are using Langflow for RAG, you can integrate with the vector database in Astra Serverless.
![Langflow reference architecture on Kubernetes](/img/langflow-reference-architecture.png)
## Environment isolation
It is recommended to deploy and run two separate environments for Langflow, with one environment reserved for development use and another for production use.
![Langflow environments](/img/langflow-env.png)
* **The Langflow development environment** must include the Integrated Development Environment (IDE) for the full experience of Langflow, optimized for prototyping and testing new flows.
* **The Langflow production environment** executes the flow logic in production and enables Langflow flows as standalone services.
## Why is it important to have separate deployments?
This separation is designed to enhance security, optimize resource allocation, and streamline management.
* **Security**
* **Isolation**: By separating the development and production environments, you can better isolate different phases of the application lifecycle. This isolation minimizes the risk of development-related issues impacting the production environments.
* **Access control**: Different security policies and access controls can be applied to each environment. Developers may require broader access in the IDE for testing and debugging, while the runtime environment can be locked down with stricter security measures.
* **Reduced attack surface**: The runtime environment is configured to include only essential components, reducing the attack surface and potential vulnerabilities.
* **Resource allocation**
* **Optimized resource usage and cost efficiency**: By separating the two environments, you can allocate resources more effectively. Each flow can be deployed independently, providing fine-grained resource control.
* **Scalability**: The runtime environment can be scaled independently based on application load and performance requirements, without affecting the development environment.

View file

@ -162,4 +162,4 @@ The test application returns a large amount of text, so the example command used
For instructions on building and pushing your image to Docker Hub, see [Docker](/deployment-docker).
To deploy your application to Kubernetes, see [Kubernetes](/deployment-kubernetes).
To deploy your application to Kubernetes, see [Deploy the Langflow production environment to Kubernetes](/deployment-kubernetes-prod).

View file

@ -250,6 +250,12 @@ const config = {
to: "/components-custom-components",
from: "/components/custom",
},
{
to: "/deployment-kubernetes-dev",
from: [
"/deployment-kubernetes",
]
},
// add more redirects like this
// {
// to: '/docs/anotherpage',

View file

@ -112,9 +112,25 @@ module.exports = {
label: "Docker"
},
{
type: "doc",
id: "Deployment/deployment-kubernetes",
label: "Kubernetes"
type: "category",
label: "Kubernetes",
items: [
{
type: "doc",
id: "Deployment/deployment-prod-best-practices",
label: "Langflow architecture and best practices"
},
{
type: "doc",
id: "Deployment/deployment-kubernetes-dev",
label: "Deploy in development"
},
{
type: "doc",
id: "Deployment/deployment-kubernetes-prod",
label: "Deploy in production"
}
]
},
{
type: "doc",
@ -135,7 +151,7 @@ module.exports = {
type: "doc",
id: "Deployment/deployment-render",
label: "Render"
}
},
],
},
{

BIN
docs/static/img/langflow-env.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB