Skip to Content
Docs远程 k3d 部署

Remote k3d Setup for BitFlow

This guide sets up a full remote Kubernetes cluster using k3d to leverage remote machine processing power while maintaining hot-reload capabilities. Uses local k3d registry for fast development, with cloud registries for production edge nodes.

Remote Machine Setup (192.168.20.187)

Step 1: Install k3d and Docker

# Install Docker sudo apt-get update sudo apt-get install -y docker.io sudo usermod -aG docker $USER sudo systemctl enable --now docker # Install k3d curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash # Install kubectl sudo apt-get install -y kubectl

Step 2: Create k3d Cluster with External Access

# Create cluster with external API access, port forwarding, and local registry k3d cluster create bitflow \ --api-port 0.0.0.0:6443 \ --port 3000:3000@loadbalancer \ --port 8080:8080@loadbalancer \ --port 9001:9001@loadbalancer \ --port 15672:15672@loadbalancer \ --port 5432:5432@loadbalancer \ --port 6379:6379@loadbalancer \ --registry-create 0.0.0.0:5000 \ --volume /tmp/k3d-bitflow:/tmp/hostpath@all # Verify cluster is running kubectl get nodes kubectl get pods -A

Step 3: Configure Firewall (if needed)

# Allow necessary ports through firewall sudo ufw allow 6443 # Kubernetes API sudo ufw allow 3000 # UI sudo ufw allow 8080 # API sudo ufw allow 5000 # k3d Registry sudo ufw allow 9001 # MinIO sudo ufw allow 15672 # RabbitMQ

Step 4: Configure kubectl for k3d Cluster

# Configure kubectl to use the k3d cluster k3d kubeconfig merge bitflow --kubeconfig-merge-default # Verify configuration kubectl config current-context # Should show: k3d-bitflow # Test cluster access kubectl cluster-info kubectl get nodes

Step 4b: Export Config for Remote Access (Optional)

# Only if you need to access from another machine k3d kubeconfig get bitflow > bitflow-kubeconfig.yaml # Show the config (to copy to local machine) cat bitflow-kubeconfig.yaml

Local Machine Setup (Your Development Machine)

Step 1: Copy kubeconfig from Remote Machine

# On remote machine, you already exported the config: # k3d kubeconfig get bitflow > bitflow-kubeconfig.yaml # Copy the kubeconfig to your local machine scp user@192.168.20.187:~/bitflow-kubeconfig.yaml ~/.kube/bitflow-kubeconfig.yaml # Or manually copy the content from: cat bitflow-kubeconfig.yaml

Step 2: Configure Local kubectl

# Method 1: Use the k3d kubeconfig directly export KUBECONFIG=~/.kube/bitflow-kubeconfig.yaml kubectl get nodes # Method 2: Merge into your existing kubectl config (improved) # First ensure ~/.kube directory exists mkdir -p ~/.kube # Create backup if config exists if [ -f ~/.kube/config ]; then cp ~/.kube/config ~/.kube/config.backup fi # Method 2a: Direct copy (simple) cp ~/.kube/bitflow-kubeconfig.yaml ~/.kube/config # Method 2b: Proper merge (if you have existing contexts to preserve) # KUBECONFIG=~/.kube/config:~/.kube/bitflow-kubeconfig.yaml kubectl config view --flatten > ~/.kube/merged-config # mv ~/.kube/merged-config ~/.kube/config # Check what context names are available kubectl config get-contexts # Set the context (use the actual context name from above) # Common names: k3d-bitflow, bitflow, or default kubectl config use-context <ACTUAL_CONTEXT_NAME> # Test connectivity kubectl get nodes kubectl cluster-info

Step 3: Alternative - Manual Configuration (if above fails)

# Extract certificate and key from the exported kubeconfig # This is a fallback method if direct kubeconfig doesn't work kubectl config set-cluster remote-bitflow \ --server=https://192.168.20.187:6443 \ --insecure-skip-tls-verify=true kubectl config set-context remote-bitflow \ --cluster=remote-bitflow kubectl config use-context remote-bitflow

Verification

Test Remote Cluster Access

# Check cluster connectivity kubectl get nodes -o wide kubectl get namespaces kubectl get pods -A

Test k3d Registry Access

# Test k3d registry connectivity curl http://192.168.20.187:5000/v2/ # Test pushing to k3d registry docker pull hello-world docker tag hello-world 192.168.20.187:5000/test:latest docker push 192.168.20.187:5000/test:latest # Verify push succeeded curl http://192.168.20.187:5000/v2/_catalog

Deploy BitFlow

Once the remote cluster is set up and accessible:

# Deploy BitFlow to remote cluster (using k3d registry for development) cd /path/to/bitflow tilt up -- --registry=192.168.20.187:5000/bitflow # Services will be accessible at: # - UI: http://192.168.20.187:3000 # - API: http://192.168.20.187:8080 # - MinIO: http://192.168.20.187:9001 # - RabbitMQ: http://192.168.20.187:15672 # Note: Uses k3d registry for fast development iteration # For production edge nodes, use cloud registry (GCR, ECR, etc.)

Troubleshooting

Connection Issues

# Test basic connectivity ping 192.168.20.187 telnet 192.168.20.187 6443 # Check k3d cluster status k3d cluster list k3d node list # View k3d logs docker logs k3d-bitflow-server-0

Registry Issues

# Check registry container docker ps | grep registry docker logs k3d-registry.localhost # Test registry from remote machine curl http://localhost:5000/v2/

Firewall Issues

# Check if ports are open sudo netstat -tlnp | grep -E '(6443|5000|3000|8080)' # Disable firewall temporarily for testing sudo ufw disable

Performance Notes

  • File Sync: Expect 100-500ms latency for file changes vs instant local
  • Image Builds: Will be faster on powerful remote machine
  • Hot Reload: Still works but with network overhead
  • Debugging: Remote logs accessible via kubectl logs and Tilt UI

This setup provides the optimal balance of remote processing power with local development convenience.

最后更新