REST API¶
kubefwd's REST API enables programmatic control over port forwarding. Build custom tooling, integrate with CI/CD pipelines, or create dashboards that dynamically manage which services are forwarded. Add and remove namespaces or individual services on the fly, query real-time metrics, stream events via SSE, and diagnose connection issues without restarting kubefwd.
Quick Start¶
# Idle mode - API enabled by default, add namespaces dynamically
sudo -E kubefwd
# Or forward a namespace with API enabled
sudo -E kubefwd svc -n default --api
# Test the API
curl http://kubefwd.internal/api/health
The API is available at http://kubefwd.internal/api.
Interactive documentation is at http://kubefwd.internal/docs.

Overview¶
| Property | Value |
|---|---|
| Base URL | http://kubefwd.internal/api |
| Authentication | None (loopback only) |
| Response Format | JSON |
| OpenAPI Spec | /openapi.yaml |
All responses use this wrapper format:
Error responses:
{
"success": false,
"data": null,
"error": {
"code": "NOT_FOUND",
"message": "Service not found"
}
}
Health & Info¶
GET /api/health¶
Health check endpoint.
GET /api/info¶
Server information and version.
Services¶
GET /api/v1/services¶
List all forwarded services.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| namespace | string | Filter by namespace |
| context | string | Filter by context |
| status | string | Filter by status (active, error) |
# List all services
curl http://kubefwd.internal/api/v1/services
# Filter by namespace
curl http://kubefwd.internal/api/v1/services?namespace=default
GET /api/v1/services/:key¶
Get a specific service. Key format: service-name.namespace.context
POST /api/v1/services¶
Add a new service to forward.
curl -X POST http://kubefwd.internal/api/v1/services \
-H "Content-Type: application/json" \
-d '{
"namespace": "default",
"service_name": "my-service",
"context": "minikube"
}'
DELETE /api/v1/services/:key¶
Stop forwarding a service.
POST /api/v1/services/:key/reconnect¶
Reconnect a specific service.
POST /api/v1/services/:key/sync¶
Sync service with Kubernetes (refresh pods).
POST /api/v1/services/reconnect¶
Reconnect all services (or all errored services).
# Reconnect all errored services
curl -X POST http://kubefwd.internal/api/v1/services/reconnect
# Force reconnect all services
curl -X POST "http://kubefwd.internal/api/v1/services/reconnect?force=true"
Forwards¶
Individual port forwards (a service may have multiple forwards for different pods/ports).
GET /api/v1/forwards¶
List all active port forwards.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| namespace | string | Filter by namespace |
| service | string | Filter by service name |
| status | string | Filter by status |
GET /api/v1/forwards/:key¶
Get details for a specific forward.
GET /api/v1/forwards/:key/http¶
Get HTTP traffic captured for a forward.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| count | integer | Number of entries (default: 50) |
Namespaces¶
Manage namespace watchers dynamically.
GET /api/v1/namespaces¶
List active namespace watchers.
GET /api/v1/namespaces/:key¶
Get details for a namespace watcher. Key format: namespace.context
POST /api/v1/namespaces¶
Add a namespace watcher (start forwarding all services in namespace).
curl -X POST http://kubefwd.internal/api/v1/namespaces \
-H "Content-Type: application/json" \
-d '{
"namespace": "staging",
"context": "minikube"
}'
DELETE /api/v1/namespaces/:key¶
Remove a namespace watcher (stop forwarding all services in namespace).
Kubernetes Discovery¶
Query the Kubernetes cluster for available resources.
GET /api/v1/kubernetes/contexts¶
List available kubeconfig contexts.
GET /api/v1/kubernetes/namespaces¶
List namespaces in a context.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| context | string | Kubernetes context (uses current if omitted) |
GET /api/v1/kubernetes/services¶
List services in a namespace.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| namespace | string | Namespace (required) |
| context | string | Kubernetes context |
GET /api/v1/kubernetes/services/:namespace/:name¶
Get details for a specific Kubernetes service.
Metrics¶
Traffic and performance metrics.
GET /api/v1/metrics¶
Summary metrics for all forwards.
{
"totalServices": 15,
"activeForwards": 23,
"totalBytesIn": 1048576,
"totalBytesOut": 524288,
"uptime": "2h15m"
}
GET /api/v1/metrics/services¶
Metrics grouped by service.
GET /api/v1/metrics/services/:key¶
Detailed metrics for a specific service.
GET /api/v1/metrics/services/:key/history¶
Historical metrics for a service (time series data).
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| duration | string | Time window (e.g., "1h", "30m") |
| interval | string | Bucket interval (e.g., "1m", "5m") |
curl "http://kubefwd.internal/api/v1/metrics/services/api-gateway.default.minikube/history?duration=1h"
Diagnostics¶
Error analysis and troubleshooting.
GET /api/v1/diagnostics¶
Diagnostics summary.
GET /api/v1/diagnostics/errors¶
List current errors.
GET /api/v1/diagnostics/services/:key¶
Diagnostics for a specific service.
GET /api/v1/diagnostics/forwards/:key¶
Diagnostics for a specific forward.
GET /api/v1/diagnostics/network¶
Network interface diagnostics.
Analysis¶
AI-friendly status and analysis endpoints.
GET /api/v1/status¶
Quick status overview optimized for AI tools.
{
"status": "healthy",
"message": "All services forwarding normally",
"totalServices": 15,
"activeServices": 15,
"errorCount": 0
}
GET /api/v1/analyze¶
Detailed analysis with recommendations.
History¶
Event and error history.
GET /api/v1/history/events¶
Recent events.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| count | integer | Number of events (default: 50) |
GET /api/v1/history/errors¶
Error history.
GET /api/v1/history/reconnections¶
All reconnection events.
GET /api/v1/services/:key/history/reconnections¶
Reconnection history for a specific service.
GET /api/v1/history/stats¶
Aggregated history statistics.
Logs¶
Application logs.
GET /api/v1/logs¶
Recent log entries.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| count | integer | Number of entries (default: 100) |
| level | string | Filter by level (debug, info, warn, error) |
| service | string | Filter by service |
GET /api/v1/logs/stream¶
Server-Sent Events (SSE) stream of logs.
GET /api/v1/logs/system¶
System-level logs.
DELETE /api/v1/logs/system¶
Clear system logs.
Events (SSE)¶
GET /api/v1/events¶
Server-Sent Events stream for real-time updates.
Event types:
service.added- New service started forwardingservice.removed- Service stopped forwardingservice.error- Service encountered an errorforward.connected- Port forward establishedforward.disconnected- Port forward lostpod.added- Pod added to servicepod.removed- Pod removed from service
Example event:
event: service.added
data: {"key":"api-gateway.default.minikube","namespace":"default","service":"api-gateway"}
HTTP Traffic¶
HTTP request/response capture for debugging.
GET /api/v1/services/:key/http¶
HTTP traffic for a service.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| count | integer | Number of entries (default: 50) |
Error Codes¶
| Code | Description |
|---|---|
NOT_FOUND |
Resource not found |
BAD_REQUEST |
Invalid request parameters |
INTERNAL_ERROR |
Server error |
ALREADY_EXISTS |
Resource already exists |
CONFLICT |
Operation conflicts with current state |
See Also¶
- Getting Started - Installation and basic usage
- MCP Integration - AI assistant integration
- Configuration - CLI flags reference