Kubernetes Context Management
Wake provides robust Kubernetes context management capabilities, allowing you to seamlessly work across multiple clusters and namespaces. This feature is essential for teams managing development, staging, and production environments.
Overview
Wake automatically detects and works with your current Kubernetes configuration, supporting multiple contexts and providing easy switching between different clusters and namespaces.
Basic Context Usage
Using Current Context
# Wake uses your current kubectl context by default
wake --ui
# Check which context Wake is using
kubectl config current-context
Specifying a Different Context
# Use a specific context for Wake operations
wake --context staging-cluster --ui
# Combine with namespace selection
wake --context production --namespace apps --ui
Context Configuration
Listing Available Contexts
# List all available Kubernetes contexts
kubectl config get-contexts
# Wake will work with any context from this list
wake --context <context-name> --ui
Setting Default Context
# Switch your default context
kubectl config use-context production-cluster
# Now Wake will use this context by default
wake --ui
Advanced Context Management
Multi-Cluster Operations
# Monitor logs from staging cluster
wake --context staging --namespace apps --ui
# Switch to production cluster in another terminal
wake --context production --namespace production --ui
# Compare logs across environments
wake --context staging -i "ERROR" --output staging-errors.log &
wake --context production -i "ERROR" --output prod-errors.log &
Context-Specific Configuration
# Set different configurations for different contexts
wake setconfig --context staging script_outdir /tmp/staging-scripts
wake setconfig --context production script_outdir /secure/prod-scripts
# View context-specific configuration
wake getconfig --context staging
Kubeconfig File Management
Custom Kubeconfig Files
# Use a specific kubeconfig file
wake --kubeconfig ~/.kube/custom-config --ui
# Combine with context selection
wake --kubeconfig ~/.kube/staging-config --context staging-cluster --ui
Multiple Kubeconfig Files
# Development environment
wake --kubeconfig ~/.kube/dev-config --ui
# Staging environment
wake --kubeconfig ~/.kube/staging-config --ui
# Production environment (default kubeconfig)
wake --ui
Namespace Management
Cross-Namespace Monitoring
# Monitor all namespaces in current context
wake --all-namespaces --ui
# Monitor specific namespaces across contexts
wake --context staging --namespace "app-*" --ui
wake --context production --namespace "prod-*" --ui
Namespace Patterns
# Use regex patterns for namespace selection
wake --context staging --namespace "test-.*" --ui
# Monitor multiple specific namespaces
wake --context production --namespace "frontend,backend,database" --ui
Environment-Specific Workflows
Development Workflow
# Quick development cluster access
export KUBECONFIG=~/.kube/dev-config
wake --ui
# Or specify directly
wake --kubeconfig ~/.kube/dev-config --namespace development --ui
Staging Validation
# Staging environment testing
wake --context staging-cluster \
--namespace staging \
--template jfr \
--template-args 1234 30s
Production Monitoring
# Production monitoring with restricted access
wake --context production-cluster \
--namespace production \
--ui \
--output-file prod-logs.txt
Security and Best Practices
Context Isolation
- Separate Kubeconfig Files: Use different kubeconfig files for different environments
- Context Validation: Always verify your current context before running commands
- Namespace Restrictions: Use specific namespaces rather than cluster-wide access when possible
Configuration Management
# Verify context before operations
kubectl config current-context
wake --ui
# Use read-only contexts for production monitoring
wake --context prod-readonly --ui
Access Control
# Limited namespace access
wake --context limited-access --namespace allowed-ns --ui
# Service account-based access
wake --kubeconfig ~/.kube/service-account-config --ui
Troubleshooting Context Issues
Common Problems
Context Not Found
# Error: context "staging" not found
# Solution: Check available contexts
kubectl config get-contexts
Permission Denied
# Error: pods is forbidden
# Solution: Verify RBAC permissions for the context
kubectl auth can-i get pods --context staging
Kubeconfig Issues
# Error: invalid configuration
# Solution: Validate kubeconfig file
kubectl config view --kubeconfig ~/.kube/custom-config
Debugging Commands
# Test context connectivity
kubectl get pods --context staging
# Verify Wake can access the context
wake --context staging --list-containers
# Check namespace permissions
kubectl get namespaces --context production
Integration Examples
CI/CD Pipeline Integration
#!/bin/bash
# Deploy and monitor script
# Deploy to staging
kubectl apply -f deployment.yaml --context staging
# Monitor deployment logs
wake --context staging --namespace apps -i "deployment" --ui
# After validation, deploy to production
kubectl apply -f deployment.yaml --context production
wake --context production --namespace production -i "deployment" --ui
Multi-Environment Monitoring
# Monitor script for multiple environments
#!/bin/bash
echo "Monitoring Development..."
wake --context dev --namespace apps -i "ERROR" --output dev-errors.log &
echo "Monitoring Staging..."
wake --context staging --namespace apps -i "ERROR" --output staging-errors.log &
echo "Monitoring Production..."
wake --context production --namespace apps -i "ERROR" --output prod-errors.log &
wait
Configuration Tips
- Use Descriptive Context Names: Name contexts clearly (e.g.,
dev-cluster,staging-us-west,prod-eu-central) - Set Default Namespaces: Configure default namespaces in your kubeconfig for each context
- Organize Kubeconfig Files: Keep separate kubeconfig files for different environments
- Test Connectivity: Always test context connectivity before important operations
- Document Access Patterns: Maintain documentation of which contexts are used for what purposes
With Wake's Kubernetes context management, you can efficiently work across multiple clusters and environments while maintaining security and organization in your log analysis workflows.