Langfuse Kubernetes deployment
Quick answer
Deploy Langfuse on Kubernetes by creating a Docker container with your Langfuse server, then defining a Kubernetes Deployment and Service manifest to run and expose it. Use environment variables for your
LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY to authenticate the service securely.PREREQUISITES
Python 3.8+Docker installedkubectl configured for your Kubernetes clusterLangfuse API keys (<code>LANGFUSE_PUBLIC_KEY</code> and <code>LANGFUSE_SECRET_KEY</code>)Basic knowledge of Kubernetes manifests
Setup Langfuse server Docker image
Langfuse requires running its server component, which you can containerize using Docker. Create a Dockerfile that installs your Python environment and Langfuse SDK, then runs your Langfuse app.
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . ./
CMD ["python", "app.py"] Step by step Kubernetes deployment
Write a Kubernetes Deployment manifest to run your Langfuse server container, passing the required environment variables for authentication. Expose it with a Service for internal or external access.
apiVersion: apps/v1
kind: Deployment
metadata:
name: langfuse-server
spec:
replicas: 1
selector:
matchLabels:
app: langfuse
template:
metadata:
labels:
app: langfuse
spec:
containers:
- name: langfuse
image: your-dockerhub-username/langfuse-server:latest
ports:
- containerPort: 8080
env:
- name: LANGFUSE_PUBLIC_KEY
valueFrom:
secretKeyRef:
name: langfuse-secrets
key: public_key
- name: LANGFUSE_SECRET_KEY
valueFrom:
secretKeyRef:
name: langfuse-secrets
key: secret_key
---
apiVersion: v1
kind: Service
metadata:
name: langfuse-service
spec:
selector:
app: langfuse
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer Common variations
- Use Kubernetes Secrets to store
LANGFUSE_PUBLIC_KEYandLANGFUSE_SECRET_KEYsecurely. - Deploy with Helm charts for easier management and upgrades.
- Configure autoscaling by adding a Horizontal Pod Autoscaler (HPA) resource.
- Use Ingress controllers to expose Langfuse with custom domains and TLS.
apiVersion: v1
kind: Secret
metadata:
name: langfuse-secrets
type: Opaque
stringData:
public_key: "your_public_key_here"
secret_key: "your_secret_key_here" Troubleshooting tips
- If Langfuse server fails to start, check container logs with
kubectl logsfor missing environment variables or dependency errors. - Verify Kubernetes Secrets are correctly created and referenced.
- Ensure your cluster allows LoadBalancer services or use NodePort for local testing.
- Check network policies or firewalls that might block access to the Langfuse service.
Key Takeaways
- Containerize your Langfuse server with a Dockerfile including environment variables for keys.
- Use Kubernetes Deployment and Service manifests to run and expose Langfuse securely.
- Store Langfuse API keys in Kubernetes Secrets to protect sensitive credentials.
- Consider Helm charts and autoscaling for production-grade deployments.
- Check logs and Kubernetes resource configurations to troubleshoot deployment issues.