Setting up a Development Environment
Tilt is a great way to run OpenCost on a local or remote Kubernetes environment. Tilt automatically redeploys OpenCost when code or configuration changes, provides easy access to back end debugging, and automatically handles port forwarding.
Prerequisites
Required
- Delve and the Delve plugin for your preferred IDE or text editor
- Docker Desktop or Docker Engine
- Go
- Helm
- kind or your preferred tool for a Kubernetes development environment
- kubectl
- Node.js
- Tilt
Run OpenCost
- In a terminal, run:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts - Update
tilt-values.yamlor create a new yaml file to contain desired attributes - see Helm chart. - Optional - configure JSON files for cloud integration(s) and a service key (see configuration documentation for more).
- Update
Tiltfileto allow your remote Kubernetes contexts, if desired. See comment block near top of theTiltfile. See Tilt documentation here. - If using
kind, in a terminal, runkind create clusterto create local cluster, or set your Kubernetes context to the desired cluster. - Configure a
tilt_config.jsonfile - see Tilt Command Options below. - In a terminal, run
tilt upat the root of the OpenCost repository. See Tilt Command Options below for more options. - Follow instructions in the terminal to open the Tilt UI in browser.
- As you update code,
tilt_config.json, ortilt-values.yaml, Tilt will automatically watch relevant source code and recompile, build, deploy, and run tests. tilt downwill tear down resources created, otherwise they will continue to run indefinitely.kind deletecluster will delete the local cluster, if desired.
Tilt Command Options
via tilt_config.json
The best way to configure OpenCost to use Tilt is with a tilt_config.json file in the root of the OpenCost repository. The file must live there; a symlink is an alternative if you wish to store it elsewhere. This file is automatically reloaded in Tilt when updated. Omitted values will use defaults.
Example file:
{
"arch":"amd64",
"cloud-integration":"../cloud-integration.json"
}
via CLI
These options can also be placed after tilt up --.
Example command:
tilt up -- --arch arm64 --docker-repo dockerhub-username --cloud-integration ../cloud-integration.json --service-key ../service-key.json
Options defined from the CLI will override those from tilt_config.json.
Options
archValue:amd64(default),arm64cloud-integrationValue: Path to a JSON file for cloud integrations Optional. Defaults to an empty string. This is the path to the JSON file to use for thecloud-integrationsecret. See configuration documentation here.delve-continueValue:true(default) orfalseOptional, defaults to true. Determines if the--continueflag is used with delve. By default, this will let applications start without a debugger attached.falsewill wait for a debugger to attach before starting.docker-repoValue: Docker Hub username or repository, defaults to an empty string. Required for a remote cluster, optional for local. Optional. This is the CPU architecture of the desired node(s) on the cluster. The value is prepended to the Docker image names (the -t flag in a Docker build command). See Docker Documentation.helm-valuesOptional. Defaults to./tilt-values.yamlThis is the path to the values.yaml file that will be used for the OpenCost Helm chart.service-keyValue: Path to a JSON file for a service key Optional. Defaults to an empty string. This is the path to the JSON file to use for theservice-keysecret. See configuration documentation.port-costmodelOptional. Defaults to 9003. This is the port forwarded to localhost for the costmodel (back end). Note: Intilt_config.json, this is a string and must be in quotes, since Tilt options must be a bool or a string.port-debugOptional. Defaults to 40000. This is the port forwarded to localhost for delve. Note: Intilt_config.json, this is a string and must be in quotes, since Tilt options must be a bool or a string.port-prometheusOptional. Defaults to 9080. This is the port forwarded to localhost for Prometheus. Note: Intilt_config.json, this is a string and must be in quotes, since Tilt options must be a bool or a string.port-uiOptional. Defaults to 9090. This is the port forwarded to localhost for the web UI. Note: Intilt_config.json, this is a string and must be in quotes, since Tilt options must be a bool or a string.
Attach Debugger to the Back End
The OpenCost back end auto starts with delve by default. Configure your IDE or text editor to attach to http://localhost:40000 (or specified value of the port-debug option).
If you want to attach the debugger at startup, remove the --continue flag from the entrypoint in the docker_build_with_restart function in the Tiltfile, then connect the debugger. Once connected, the OpenCost back end will start.

