#
Local Development with Tilt
This document describes how to use Tilt for local development of the Kubebrowse project on Kubernetes. Tilt provides a streamlined workflow with live updates, automated builds, and easy resource management.
#
Prerequisites
- Docker: Ensure Docker is installed and running. Tilt uses Docker to build container images. (https://docs.docker.com/get-docker/)
- Kubernetes Cluster: You need a local Kubernetes cluster. Options include:
- Kind (Kubernetes IN Docker)
- Minikube
- Docker Desktop's built-in Kubernetes cluster.
Ensure your
kubectlcontext is pointing to your local development cluster (kubectl config current-context).
- Tilt: Install Tilt by following the instructions on the official Tilt website: Install Tilt
#
Getting Started
Clone the Repository: If you haven't already, clone the project repository:
git clone https://github.com/browsersec/KubeBrowse cd KubeBrowseConfigure Kubernetes Context (if needed): The
Tiltfileattempts to use your current Kubernetes context. If Tilt has trouble connecting or you need to specify a context:Uncomment and modify the
allow_k8s_contextsline in theTiltfileat the root of the project. For example:# allow_k8s_contexts('kind-kind', 'docker-desktop')Replace
'kind-kind'or'docker-desktop'with the name of yourkubectlcontext.
Start Tilt: Navigate to the root directory of the project in your terminal and run:
tilt upTilt will:
- Build the container images for the frontend and backend services.
- Deploy all resources defined in
deployments/manifest.ymlto your Kubernetes cluster. - Set up port forwarding for accessing the services locally:
- Backend API (
browser-sandbox-api):localhost:4567 - Frontend (
browser-sandbox-frontend):localhost:3000
- Backend API (
- Open a web browser with the Tilt UI, where you can monitor the status of your services, view logs, and manage resources.
Accessing the Application:
- Frontend: Open your browser and go to
http://localhost:3000 - API: Accessible at
http://localhost:4567
- Frontend: Open your browser and go to
#
Development Workflow
Live Updates:
- Backend (Go): When you save changes to Go files in the
./api,./cmd, or./internaldirectories, Tilt will automatically sync the changes to the running container, rebuild the Go application, and restart the pod. - Frontend (Vite/React): When you save changes to files in the
./frontend/srcdirectory (or other relevant frontend paths likeindex.html,package.json), Tilt will sync the files.- If
package.jsonorbun.lockbchanges, dependencies will be reinstalled, and static assets will be rebuilt. - Caddy will serve the updated static files. You may need to refresh your browser to see these changes.(Note: For a Hot Module Replacement (HMR) experience with Vite, the frontend Dockerfile's CMD and Tiltfile's port-forwarding would need to be adjusted to use Vite's dev server directly.)
- If
- Backend (Go): When you save changes to Go files in the
Logs: View real-time logs for each service in the Tilt UI.
Resource Management: The Tilt UI allows you to manually trigger updates, restart pods, and view Kubernetes resource details.
#
Stopping Tilt
- To stop Tilt and remove the deployed resources from your Kubernetes cluster, press
Ctrl+Cin the terminal wheretilt upis running. - Alternatively, you can use
tilt down.
#
Troubleshooting
tilt doctor: Runtilt doctorin your terminal. This command checks your Tilt and Kubernetes setup and provides suggestions for fixing common issues.- Kubernetes Context: Ensure
kubectl config current-contextpoints to the correct local cluster. If not, usekubectl config use-context <your-local-cluster-context>. - Image Pull Issues: If Kubernetes has trouble pulling images, ensure your
imagePullPolicyindeployments/manifest.ymlisIfNotPresentfor the services managed by Tilt (api, frontend). This should already be set by a previous step. Also, check your local Docker environment and Kubernetes cluster's ability to access local images (e.g., if using Minikube, you might needminikube image load <image_name>or configure Docker environment sharing). Theupdate_mode(UPDATE_MODE_AUTO)in Tiltfile usually handles this for local clusters. - Port Conflicts: If the default ports (4567 for API, 3000 for frontend) are already in use on your local machine, you can change the local port in the
port_forwardssection of theTiltfile. For example, changeport_forwards=['3000:80']toport_forwards=['3001:80']to uselocalhost:3001for the frontend.
This setup should significantly improve the local development experience when working with Kubernetes.