A Kubernetes-native implementation of the Open Runtimes Executor, built with TypeScript, Bun, and Hono.js. This service provides a stateless HTTP API for creating and executing serverless functions within Kubernetes clusters.
Open Runtimes K8s Executor is a JavaScript/TypeScript rewrite of the original Open Runtimes Executor (PHP), designed specifically for Kubernetes environments. It maintains API compatibility with the original executor while leveraging Kubernetes primitives for container orchestration, resource management, and scalability.
- Kubernetes-Native: Uses Kubernetes Jobs and Pods for runtime execution, fully integrated with K8s resource management
- Stateless Architecture: Horizontally scalable as a Kubernetes Deployment with no shared state
- Runtime Management: Create, list, and manage runtime environments with full lifecycle control
- Background Cleanup: Automatic cleanup of completed/failed jobs using a leader election mechanism via Kubernetes Leases
- S3 Storage Integration: Supports S3-compatible storage for function source code and artifacts
- Multi-Version Support: Compatible with Open Runtimes v2 and v5
- High Performance: Built on Bun runtime and Hono.js framework for optimal performance
- Production Ready: Includes graceful shutdown, health checks, and comprehensive error handling
The executor operates as a stateless HTTP service that:
- Accepts runtime creation and execution requests via REST API
- Creates Kubernetes Jobs for building function artifacts
- Manages Kubernetes Deployments for long-running runtime servers
- Executes functions in isolated Pods with configurable resource limits
- Automatically cleans up completed jobs and inactive runtimes
- API Server: Hono.js-based HTTP server handling executor API endpoints
- Kubernetes Client: Manages K8s resources (Jobs, Deployments, Pods, Services)
- Maintenance Loop: Background worker with leader election for cleanup tasks
- S3 Client: Handles function source code storage and retrieval
- Kubernetes cluster (1.20+)
- kubectl configured to access your cluster
- S3-compatible storage (or compatible object storage)
- Docker image registry (for runtime images)
- Build the Docker image:
docker build -t your-registry/open-runtimes-k8s-executor:latest .
docker push your-registry/open-runtimes-k8s-executor:latest- Deploy to Kubernetes:
kubectl apply -k deploy/For detailed deployment instructions, configuration, and troubleshooting, see deploy/README.md.
The executor provides the same API interface as the original Open Runtimes Executor:
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/health |
Health check endpoint |
| POST | /v1/runtimes |
Create a new runtime server |
| GET | /v1/runtimes |
List currently active runtimes |
| GET | /v1/runtimes/{runtimeId} |
Get a runtime by its ID |
| DELETE | /v1/runtimes/{runtimeId} |
Delete a runtime |
| POST | /v1/runtimes/{runtimeId}/executions |
Execute a function |
| GET | /v1/runtimes/{runtimeId}/logs |
Get live stream of logs |
# Create a runtime
curl -X POST http://localhost:8080/v1/runtimes \
-H "Authorization: Bearer your-secret-key" \
-H "Content-Type: application/json" \
-d '{
"runtimeId": "my-function",
"image": "openruntimes/php:v5-8.3",
"source": "s3://bucket/my-function.tar.gz",
"entrypoint": "index.php"
}'
# Execute the function
curl -X POST http://localhost:8080/v1/runtimes/my-function/executions \
-H "Authorization: Bearer your-secret-key" \
-H "Content-Type: application/json" \
-d '{
"body": "{\"name\": \"World\"}",
"path": "/",
"method": "POST",
"headers": {}
}'| Variable | Description | Example |
|---|---|---|
OPR_EXECUTOR_SECRET |
Secret key for API authentication | openssl rand -hex 32 |
S3_ENDPOINT |
S3-compatible storage endpoint URL | https://s3.amazonaws.com |
S3_BUCKET |
S3 bucket name for function storage | my-functions-bucket |
S3_ACCESS_KEY_ID |
S3 access key ID | AKIAIOSFODNN7EXAMPLE |
S3_SECRET_ACCESS_KEY |
S3 secret access key | wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |
| Variable | Description | Default |
|---|---|---|
KUBERNETES_NAMESPACE |
Namespace for runtime pods | appwrite-executor |
S3_REGION |
S3 region | us-east-1 |
PORT |
HTTP server port | 3000 |
OPR_EXECUTOR_MAINTENANCE_INTERVAL |
Maintenance loop interval (seconds) | 60 |
OPR_EXECUTOR_INACTIVE_THRESHOLD |
Inactive runtime cleanup threshold (seconds) | 300 |
NODE_ENV |
Node environment | production |
The executor requires the following Kubernetes permissions:
- Jobs: Create, read, delete (for build and cleanup jobs)
- Deployments: Create, read, update, delete (for runtime servers)
- Pods: Read, exec (for execution and log streaming)
- Services: Create, read, delete (for runtime service exposure)
- Leases: Create, read, update (for leader election)
See deploy/rbac.yaml for the complete RBAC configuration.
- Bun runtime (latest version)
- Node.js 18+ (for TypeScript tooling)
# Install dependencies
bun install
# Run development server
bun dev
# Run type checking
bun run typecheck
# Run linting and formatting
bun run checksrc/
├── index.ts # Main application entry point
├── routes/
│ └── runtimes.ts # Runtime API routes
├── k8s/
│ ├── client.ts # Kubernetes client initialization
│ └── definitions.ts # K8s resource definitions
├── maintenance/
│ └── loop.ts # Background cleanup loop with leader election
├── middleware/
│ └── auth.ts # Authentication middleware
├── s3/
│ ├── config.ts # S3 client configuration
│ └── scripts.ts # S3 utility functions
└── utils/
├── delay.ts # Utility functions
├── errors.ts # Error handling
├── logs.ts # Log parsing utilities
├── multipart.ts # Multipart response handling
├── pod-exec.ts # Pod execution utilities
└── runtime.ts # Runtime management utilities
While maintaining API compatibility, this Kubernetes implementation differs in several ways:
- Container Orchestration: Uses Kubernetes Jobs/Deployments instead of Docker directly
- Storage: Requires S3-compatible storage (no local filesystem option)
- Scaling: Designed for horizontal scaling in Kubernetes
- Cleanup: Uses Kubernetes Leases for distributed leader election
- Resource Management: Leverages Kubernetes resource quotas and limits
The executor is stateless and can be scaled horizontally. It exposes a health endpoint at /v1/health for Kubernetes liveness and readiness probes.
For production deployment best practices, scaling, resource limits, and high availability configuration, see deploy/README.md.
For deployment-related troubleshooting (pods, permissions, secrets, etc.), see deploy/README.md.
Contributions are welcome! Please ensure:
- Code follows the existing style (enforced by Biome)
- All tests pass
- Type checking passes (
bun run typecheck) - Linting passes (
bun run check)
This project is licensed under the MIT License - see the LICENSE.txt file for details.
- Open Runtimes Executor - Original PHP implementation
- Open Runtimes - Runtime environments for serverless computing
- Open Runtimes Proxy - Load balancer for Open Runtimes
For issues, questions, or contributions, please open an issue on GitHub.