Service Intercepts

What are Service Intercepts?

Service Intercepts allow developers to route traffic from a running service in an environment directly to their workspace for debugging and testing. When a service is intercepted, all incoming traffic is redirected to the workspace instead of the original service.

BEFORE
Normal Flow

Client Request

Environment

api-service:8080

Traffic flows to service in environment

AFTER
Intercepted Flow

Client Request

Environment

api-service:8080
BYPASSED
↓ Redirected ↓

Workspace

localhost:8080

Traffic flows to workspace instead

Normal traffic flow
Intercepted traffic
Service bypassed

How Service Intercepts Work

1

Enable Intercept

From your workspace, you activate an intercept for a specific service running in an environment (e.g., api-service)

2

Traffic Redirection

All incoming requests to the service are automatically redirected to your workspace. The original service is bypassed completely.

3

Debug & Test

Handle requests directly in your workspace with your local code changes. Set breakpoints, inspect variables, and test fixes in real-time with live traffic.

4

Disable Intercept

When you're done debugging, disable the intercept and traffic automatically flows back to the original service in the environment.

Using Service Intercepts

Prerequisite

You must first connect to an environment using kl env connect before you can intercept services. Service intercepts only work within a connected environment.

Use the kl intercept start command from within your workspace to intercept a service running in the connected environment.

Interactive Mode (Recommended)

Run the command without arguments to see a list of available services in the connected environment and select one interactively using fuzzy-find.

kl intercept start

This will display all services in the environment and let you select using arrow keys and search. You'll then be prompted to configure port mappings.

Intercept Specific Service

If you know the service name, you can intercept it directly:

kl intercept start api-server
kl intercept start backend-api
kl i s api-server          # Using aliases

Port Mapping Configuration

When you start an intercept, you need to map service ports to your workspace ports. For example, if the service runs on port 8080, you might map it to port 3000 in your workspace where your local development server is running.

Example Mapping:

  • Service port 8080 → Workspace port 3000
  • Service port 9090 → Workspace port 9090 (same port)

Managing Intercepts

List Active Intercepts

View all active service intercepts in the connected environment:

kl intercept list
kl i ls              # Using aliases

Output shows:

  • Service name and phase (Pending, Active, Failed)
  • Port mappings (service port → workspace port)
  • Error messages for failed intercepts

Check Intercept Status

Get detailed status information about a specific service intercept:

kl intercept status api-server
kl i st api-server              # Using aliases

Detailed information includes:

  • Service and workspace details
  • Phase and status messages
  • Port mappings
  • Workspace pod details (name, IP address)
  • List of affected pods
  • Intercept start time

Stop Service Intercept

Stop intercepting a service and restore normal traffic routing. You can use interactive mode or specify the service name directly:

kl intercept stop              # Interactive selection
kl intercept stop api-server   # Stop specific service
kl i sp api-server             # Using aliases

After stopping, traffic will automatically route back to the original service in the environment within ~30 seconds.

Use Cases

Debug with Real Traffic

Intercept a service to debug issues using real incoming requests from other services or external clients. Set breakpoints and inspect variables with actual production-like data.

Test API Changes

Test new API endpoints or modifications by intercepting the service and handling requests from dependent services without deploying changes to the environment.

Develop with Service Integration

Develop new features locally while staying integrated with other running services in the environment. Your workspace receives real requests from other services.

Performance Testing

Profile and optimize your service by intercepting it and analyzing performance with real traffic patterns and load from the environment.

Reproduce and Fix Bugs

Reproduce bugs that only occur with specific service interactions or data by intercepting traffic and iterating on fixes in real-time.

Safe Testing Environment

Service intercepts let you safely test and debug with live traffic without affecting the actual service running in the environment. Stop the intercept anytime to restore normal operation.