Tilt
A tool for local Kubernetes development environments
A tool for local Kubernetes development environments
Tilt is a local Kubernetes development environment tool released in 2018, and its core feature is "live update," which automatically builds, pushes, and deploys whenever code changes. It can be seen as a tool that brings the convenience of Docker Compose to Kubernetes.
The development environment is defined with a Python-based script called a Tiltfile. docker_build defines image builds, k8s_yaml defines manifests, and k8s_resource defines resource settings. When a code change is detected, it either syncs only the changed files into the container (Live Update) or performs a full build.
Tilt's web UI shows the build status, logs, and errors of all services on a single screen. Build times and deployment times are displayed in real time, making it easy to identify bottlenecks. When a problem occurs, you can check the logs and status of the relevant service with one click.
In practice, it is used when developing multiple services at the same time in a microservices environment. Only the service a developer is responsible for runs from local code, while the rest use images from the cluster. On average, the build-deploy cycle is shortened from 5 minutes to within 10 seconds.
# Tiltfile μμ
# λ§μ΄ν¬λ‘μλΉμ€ κ°λ° νκ²½ μ€μ
# μμ‘΄μ± μλ Helm μ°¨νΈ μ€μΉ (Redis, PostgreSQL)
load('ext://helm_resource', 'helm_resource')
helm_resource('redis', 'bitnami/redis', namespace='dev')
helm_resource('postgresql', 'bitnami/postgresql', namespace='dev')
# API μλΉμ€ - Live Update νμ±ν
docker_build(
'myapp/api-service',
'./services/api',
dockerfile='./services/api/Dockerfile',
live_update=[
# μμ€ μ½λλ§ λκΈ°ν (λΉλ μμ΄)
sync('./services/api/src', '/app/src'),
# package.json λ³κ²½ μ npm install μ€ν
run('npm install', trigger=['./services/api/package.json']),
]
)
# Web νλ‘ νΈμλ - Hot Reload
docker_build(
'myapp/web',
'./services/web',
dockerfile='./services/web/Dockerfile.dev',
live_update=[
sync('./services/web/src', '/app/src'),
sync('./services/web/public', '/app/public'),
]
)
# Worker μλΉμ€ - μ 체 λΉλ
docker_build(
'myapp/worker',
'./services/worker',
dockerfile='./services/worker/Dockerfile'
)
# Kubernetes λ§€λνμ€νΈ μ μ©
k8s_yaml([
'./k8s/api-deployment.yaml',
'./k8s/web-deployment.yaml',
'./k8s/worker-deployment.yaml',
])
# 리μμ€ μ€μ
k8s_resource(
'api-service',
port_forwards='8080:8080', # localhost:8080μΌλ‘ μ κ·Ό
resource_deps=['redis', 'postgresql'], # μμ‘΄μ±
labels=['backend']
)
k8s_resource(
'web',
port_forwards='3000:3000',
resource_deps=['api-service'],
labels=['frontend']
)
k8s_resource(
'worker',
resource_deps=['redis'],
labels=['backend']
)
# κ°λ° νΈμ μ€μ
config.define_bool("debug")
cfg = config.parse()
if cfg.get("debug"):
# λλ²κ·Έ λͺ¨λμμ μΆκ° μ€μ
local_resource(
'db-seed',
cmd='npm run db:seed',
deps=['./seeds'],
labels=['setup']
)
# μ€ν: tilt up
# UI μ μ: http://localhost:10350
Senior: "It's hard to run all 12 microservices locally. How about using Tilt to apply live update only to the service I'm developing and using the cluster's versions for the rest?"
Junior: "What is Live Update? Does that mean I don't have to build the image every time?"
Senior: "It only syncs the source files into the container. With Node.js, nodemon restarts automatically, so changes take effect as soon as you save."
Interviewer: "How did you set up your local Kubernetes development environment?"
Candidate: "I used Tilt. I defined the build and deployment for each service in the Tiltfile, and used live_update to sync code changes directly into the container. The development cycle was shortened from 3 minutes, including the image build, to 5 seconds, and being able to see the status of all services at a glance in the web UI made debugging easier too."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Reviewer: "The Tiltfile has only docker_build without live_update. Doing a full build every time is slow."
Developer: "Since it's Node.js, if I sync only /app/src with sync, nodemon will restart it. I'll add live_update."