tilt
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTilt — Kubernetes Dev Toolkit
Tilt — Kubernetes 开发工具包
Tilt automates the local Kubernetes development loop: watch files, build images, deploy to cluster. Configuration lives in a (Starlark, a Python dialect). A resource bundles an image build + k8s deploy (or a local command) into a single manageable unit.
TiltfileTilt 可自动化本地 Kubernetes 开发循环:监听文件、构建镜像、部署到集群。配置信息存储在 (基于Starlark,一种Python方言)中。资源将镜像构建 + Kubernetes部署(或本地命令)捆绑为一个可管理的单元。
TiltfileCLI Operations
CLI 操作
The commands an agent uses to interact with a running Tilt instance.
以下是Agent与运行中的Tilt实例交互时使用的命令。
Lifecycle
生命周期
| Task | Command |
|---|---|
| Start dev environment | |
| Start with terminal log streaming | |
| Start specific resources only | |
| Run in CI/batch mode (exits on success/failure) | |
| Stop and delete deployed resources | |
| Change runtime Tiltfile args | |
| Change runtime args (clear all) | |
On Ctrl+C from : K8s and Docker Compose resources keep running. Local processes stop. Use to clean up.
tilt upserve_cmdtilt down| 任务 | 命令 |
|---|---|
| 启动开发环境 | |
| 启动并在终端流式输出日志 | |
| 仅启动特定资源 | |
| 以CI/批量模式运行(成功/失败后退出) | |
| 停止并删除已部署的资源 | |
| 修改运行时Tiltfile参数 | |
| 修改运行时参数(清空所有) | |
在中按下Ctrl+C时:Kubernetes和Docker Compose资源会继续运行。本地进程会停止。使用来清理资源。
tilt upserve_cmdtilt downViewing Logs
查看日志
| Task | Command |
|---|---|
| Stream all logs | |
| Stream logs for one resource | |
| Show only errors | |
| Show build logs only | |
| Show runtime logs only | |
| Logs since 5 minutes ago | |
| Last 100 lines | |
| JSON output (for parsing) | |
| 任务 | 命令 |
|---|---|
| 流式输出所有日志 | |
| 流式输出单个资源的日志 | |
| 仅显示错误日志 | |
| 仅显示构建日志 | |
| 仅显示运行时日志 | |
| 显示最近5分钟的日志 | |
| 显示最后100行日志 | |
| JSON格式输出(用于解析) | |
Resource Management
资源管理
| Task | Command |
|---|---|
| List all resources | |
| Resource status as JSON | |
| Describe a resource in detail | |
| Force rebuild a resource | |
| Enable a disabled resource | |
| Disable a resource | |
| Wait for resource readiness | |
| 任务 | 命令 |
|---|---|
| 列出所有资源 | |
| 以JSON格式查看资源状态 | |
| 查看资源的详细描述 | |
| 强制重建资源 | |
| 启用已禁用的资源 | |
| 禁用资源 | |
| 等待资源就绪 | |
Inspection & Debugging
检查与调试
| Task | Command |
|---|---|
| Diagnostics (versions, cluster) | |
| Inspect file watches | |
| Describe a specific file watch | |
| Full engine state dump (JSON) | |
| Full UI state dump | |
| Test Docker build as Tilt would | |
| List API resource types | |
The Tilt API server runs on by default. All commands talk to it.
localhost:10350tilt get/describe/trigger| 任务 | 命令 |
|---|---|
| 诊断(版本、集群信息) | |
| 查看文件监听列表 | |
| 查看特定文件监听的详情 | |
| 导出完整引擎状态(JSON格式) | |
| 导出完整UI状态 | |
| 测试Tilt方式的Docker构建 | |
| 列出API资源类型 | |
Tilt API服务器默认运行在。所有命令都会与它通信。
localhost:10350tilt get/describe/triggerBuild Strategy Selector
构建策略选择器
| Situation | Function | Key detail |
|---|---|---|
| Standard Dockerfile | | Watches context dir, auto-injects into k8s |
| Custom toolchain (Bazel, ko, Buildpacks) | | Must tag with |
| Non-Docker builder (Buildah, kaniko) | | Builder handles push independently |
| Docker Compose services | | Manages compose lifecycle |
| Helm charts | | Renders locally, deploys to cluster |
| Kustomize overlays | | Renders locally, deploys to cluster |
| 场景 | 函数 | 关键细节 |
|---|---|---|
| 标准Dockerfile | | 监听上下文目录,自动注入到Kubernetes中 |
| 自定义工具链(Bazel、ko、Buildpacks) | | 必须使用 |
| 非Docker构建工具(Buildah、kaniko) | | 构建工具独立处理镜像推送 |
| Docker Compose服务 | | 管理Compose的生命周期 |
| Helm图表 | | 本地渲染,部署到集群 |
| Kustomize覆盖层 | | 本地渲染,部署到集群 |
Live Update Decision Tree
实时更新决策树
Live update replaces full image rebuilds with in-place container file syncs — seconds instead of minutes.
| Step | Purpose | Ordering |
|---|---|---|
| Force full rebuild when these files change | Must come first |
| Copy changed files into running container | After fall_back_on |
| Execute command in container (e.g., install deps) | After sync |
| Restart the container process | Must come last |
python
docker_build('myapp', '.', live_update=[
fall_back_on(['requirements.txt']),
sync('./src', '/app/src'),
run('pip install -r requirements.txt', trigger=['requirements.txt']),
])When live update breaks: Changes to files outside the context trigger a full rebuild. Changes outside any path also trigger a full rebuild. First always does a full build — live update requires a running container.
docker_buildsync()tilt up实时更新通过容器内文件同步替代完整镜像重建——耗时从分钟级缩短到秒级。
| 步骤 | 目的 | 顺序 |
|---|---|---|
| 当这些文件变更时强制完整重建 | 必须放在最前面 |
| 将变更的文件复制到运行中的容器内 | 在fall_back_on之后 |
| 在容器内执行命令(例如安装依赖) | 在sync之后 |
| 重启容器进程 | 必须放在最后 |
python
docker_build('myapp', '.', live_update=[
fall_back_on(['requirements.txt']),
sync('./src', '/app/src'),
run('pip install -r requirements.txt', trigger=['requirements.txt']),
])实时更新失效场景: 当上下文外的文件变更时会触发完整重建。不在任何路径下的文件变更也会触发完整重建。首次始终会执行完整构建——实时更新需要容器处于运行状态才能生效。
docker_buildsync()tilt upResource Configuration
资源配置
python
undefinedpython
undefinedKubernetes resource with port forwarding and dependencies
带端口转发和依赖的Kubernetes资源
k8s_resource('frontend',
port_forwards=['3000:3000'],
resource_deps=['api', 'database'],
labels=['web'],
trigger_mode=TRIGGER_MODE_MANUAL,
)
k8s_resource('frontend',
port_forwards=['3000:3000'],
resource_deps=['api', 'database'],
labels=['web'],
trigger_mode=TRIGGER_MODE_MANUAL,
)
Local resource (build tool, test runner, code generator)
本地资源(构建工具、测试运行器、代码生成器)
local_resource('codegen',
cmd='make generate',
deps=['./proto'],
labels=['tools'],
)
local_resource('codegen',
cmd='make generate',
deps=['./proto'],
labels=['tools'],
)
Local server (runs continuously)
本地服务器(持续运行)
local_resource('storybook',
serve_cmd='npm run storybook',
deps=['./src/components'],
allow_parallel=True,
readiness_probe=probe(http_get=http_get_action(port=6006)),
)
**Parallelism:** Local resources run serially by default. Set `allow_parallel=True` for independent resources. Image builds default to 3 concurrent — adjust with `update_settings(max_parallel_updates=N)`.
**Dependencies:** `resource_deps` gates on first-ever readiness only — once a dependency is ready once, dependents unlock permanently for that session.local_resource('storybook',
serve_cmd='npm run storybook',
deps=['./src/components'],
allow_parallel=True,
readiness_probe=probe(http_get=http_get_action(port=6006)),
)
**并行性:** 本地资源默认串行运行。对于独立资源,设置`allow_parallel=True`。镜像构建默认支持3个并发任务——可通过`update_settings(max_parallel_updates=N)`调整。
**依赖关系:** `resource_deps`仅在首次就绪时生效——一旦依赖项首次就绪,在本次会话中依赖它的资源将永久解锁。Debugging Flow
调试流程
Service crashing? → tilt logs -f <resource> --source runtime
Build failing? → tilt logs -f <resource> --source build
tilt docker -- build <args> (reproduces Tilt's exact build)
Wrong files rebuild? → tilt get filewatches
tilt describe filewatch <name>
Check .tiltignore, watch_settings(ignore=), ignore= param
Force a rebuild? → tilt trigger <resource>
Resource stuck? → tilt describe uiresource <name>
Check resource_deps chain
For CRDs: pod_readiness='ignore'
General diagnostics? → tilt doctor
Full state dump? → tilt dump engine | jq .服务崩溃? → tilt logs -f <resource> --source runtime
构建失败? → tilt logs -f <resource> --source build
tilt docker -- build <args> (复现Tilt的构建流程)
文件重建异常? → tilt get filewatches
tilt describe filewatch <name>
检查.tiltignore、watch_settings(ignore=)、ignore=参数
强制重建? → tilt trigger <resource>
资源卡住? → tilt describe uiresource <name>
检查resource_deps依赖链
对于CRD:设置pod_readiness='ignore'
常规诊断? → tilt doctor
导出完整状态? → tilt dump engine | jq .Top 10 Pitfalls
十大常见陷阱
| Pitfall | Fix |
|---|---|
| Wrap with |
| Live update paths outside docker_build context | Ensure sync local paths fall within context dir |
| Local resources block each other | Set |
| It only checks first-ever readiness, not current version |
| Starlark has no while/try-except/class/recursion | Use for loops, |
| Use |
| Build script MUST tag the image with this env var |
| Trigger paths must also be covered by a sync step |
First | Live update cannot work until a container is running |
| CRD pods stuck in pending | Set |
| 陷阱 | 解决方法 |
|---|---|
| 用 |
| 实时更新路径在docker_build上下文之外 | 确保同步的本地路径在上下文目录内 |
| 本地资源相互阻塞 | 对独立资源设置 |
| 它仅检查首次就绪状态,不检查当前版本 |
| Starlark不支持while/try-except/class/递归 | 使用for循环、 |
| 使用 |
custom_build中未使用 | 构建脚本必须使用此环境变量为镜像打标签 |
| 触发路径必须被某个sync步骤覆盖 |
首次 | 实时更新需要容器运行后才能生效 |
| CRD Pod卡在Pending状态 | 在CRD资源上设置 |
Additional Resources
其他资源
Reference Files
参考文档
For detailed API signatures and advanced patterns, consult:
- — Complete Tiltfile API catalog organized by category, Starlark language notes, ignore mechanism comparison
references/api-reference.md - — Multi-service architectures, environment config, CI integration, performance optimization, programmatic Tilt interaction, extension ecosystem
references/patterns.md
如需详细的API签名和高级模式,请参考:
- — 按类别组织的完整Tiltfile API目录、Starlark语言说明、忽略机制对比
references/api-reference.md - — 多服务架构、环境配置、CI集成、性能优化、程序化Tilt交互、扩展生态系统
references/patterns.md