Environment Connection allows workspaces to connect to environments and access their services directly by name. When a workspace connects to an environment, its network namespace switches to enable seamless access to all services running in that environment.
Network Namespace Switching
When you connect a workspace to an environment, the workspace's network namespace switches to access services from the environment by their names (e.g.,postgres,redis).
By default, a workspace runs in its own isolated network namespace. It has access to external internet but cannot directly access environment services.
When you connect the workspace to an environment, the workspace's network configuration changes. The workspace can now resolve environment service names through DNS.
Services are now accessible using their service names as hostnames. For example, connect to PostgreSQL at postgres:5432 or Redis at redis:6379.
Use the kl env connect command from within your workspace to connect to an environment. This switches your workspace's network namespace to access environment services.
Run the command without arguments to see a list of available environments and select one interactively using fuzzy-find.
kl env connect
This will display all available environments and let you select using arrow keys and search.
If you know the environment name, you can connect directly:
kl env connect my-env
kl env connect team-env
kl e c test-env # Using aliases
postgres, redis)After connecting to an environment, all services running in that environment become accessible using their service names as hostnames. You no longer need fully qualified domain names or IP addresses.
How It Works
When you connect to an environment, your workspace's DNS configuration is updated to resolve service names to their cluster IPs. This means:
postgres resolves to its cluster IPredis resolves to its cluster IPapi-server resolves to its cluster IPAccess services directly from your workspace terminal using their service names:
# Connect to PostgreSQL
psql -h postgres -p 5432 -U myuser -d myapp
# Connect to Redis
redis-cli -h redis -p 6379
# Ping a service
ping postgres
# Check service connectivity
curl http://api-server:8080/health
Use service names directly in your application configuration and code:
# Environment Variables (.env)
DATABASE_URL=postgresql://user:pass@postgres:5432/myapp REDIS_URL=redis://redis:6379 API_ENDPOINT=http://api-server:8080
# Node.js Example
const redis = require('redis');
const client = redis.createClient({
host: 'redis',
port: 6379
});# Python Example
import psycopg2
conn = psycopg2.connect(
host="postgres",
port=5432,
database="myapp"
)Use kl env status to see all services available in the connected environment:
kl env status
This command shows the environment name, namespace, and lists all available services with their ports.
Port Numbers
Always specify the port number when connecting to services (e.g., postgres:5432). The service name alone won't include the port.
Develop your application code in the workspace while connecting to real databases, caches, and APIs running in the environment
Run database migrations from your workspace directly against the environment database
Test your code against production-like services and debug issues in a realistic environment setup
Connect to different environments as needed to test against various service configurations and data sets
Seamless Development Experience
Environment connection eliminates the need to run services locally or manage complex port forwarding. Simply connect and start coding against real services.