πŸ”§ DevOps

Tilt

A tool for local Kubernetes development environments

Detailed Explanation

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.

Code Example

# 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

How It's Said in Practice

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."

Cautions

Learn More