☁️ Cloud
Fly.io
Fly.io
A platform for deploying apps to edge locations worldwide. Container-based.
Fly.io
A platform for deploying apps to edge locations worldwide. Container-based.
Fly.io is a cloud platform that lets you deploy applications at the edge across more than 35 regions worldwide. It uses Firecracker microVM technology to provide faster boot times than containers and strong isolation, and runs apps at the location closest to users.
Key features of Fly.io:
Pricing features:
# Fly CLI 설치 (macOS)
brew install flyctl
# 로그인
fly auth login
# 새 앱 생성 및 배포 (Dockerfile 기반)
fly launch
# ? Would you like to copy its configuration to the new app? Yes
# ? Choose a region for deployment: nrt (Tokyo, Japan)
# ? Would you like to set up a Postgresql database now? No
# 배포
fly deploy
# 앱 상태 확인
fly status
# 로그 확인
fly logs
# SSH 접속
fly ssh console
# 환경 변수 설정
fly secrets set DATABASE_URL="postgres://..."
# 스케일링 (인스턴스 수)
fly scale count 3
# 리전 추가 (글로벌 배포)
fly regions add icn # 서울
fly regions add sin # 싱가포르
fly regions add fra # 프랑크푸르트
# 머신 크기 조정
fly scale vm shared-cpu-2x --memory 1024
# 자동 스케일링 설정
fly autoscale set min=2 max=10
# PostgreSQL 생성
fly postgres create --name my-db --region nrt
# 앱에 DB 연결
fly postgres attach my-db
# fly.toml - Fly.io 앱 설정 파일
app = "my-app"
primary_region = "nrt" # 도쿄 (한국에서 가장 가까움)
[build]
dockerfile = "Dockerfile"
[env]
NODE_ENV = "production"
PORT = "8080"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true # 유휴 시 자동 정지
auto_start_machines = true # 요청 시 자동 시작
min_machines_running = 1 # 최소 1개는 항상 실행
processes = ["app"]
[http_service.concurrency]
type = "requests"
hard_limit = 250
soft_limit = 200
[[services]]
protocol = "tcp"
internal_port = 8080
[[services.ports]]
port = 80
handlers = ["http"]
[[services.ports]]
port = 443
handlers = ["tls", "http"]
[[services.tcp_checks]]
grace_period = "10s"
interval = "15s"
timeout = "2s"
[[services.http_checks]]
interval = "10s"
timeout = "2s"
grace_period = "5s"
method = "GET"
path = "/health"
protocol = "http"
[[vm]]
cpu_kind = "shared"
cpus = 1
memory_mb = 512
# 멀티 리전 배포 설정
[[regions]]
region = "nrt" # 도쿄
count = 2
[[regions]]
region = "icn" # 서울 (가능한 경우)
count = 1
[[regions]]
region = "sin" # 싱가포르
count = 1
# 볼륨 마운트 (영구 스토리지)
[[mounts]]
source = "data"
destination = "/data"
# 릴리스 명령어 (배포 후 실행)
[deploy]
release_command = "npm run db:migrate"
# Fly.io 멀티 리전 배포 전략
# 1. 리전별 인스턴스 배포
fly regions add nrt icn sin syd
# 현재 리전 확인
fly regions list
# Region Pool:
# icn (Seoul)
# nrt (Tokyo)
# sin (Singapore)
# syd (Sydney)
# 2. 리전별 스케일링
fly scale count 2 --region nrt
fly scale count 2 --region icn
fly scale count 1 --region sin
# 3. 리전별 환경 변수 (선택적)
# Fly는 FLY_REGION 환경 변수를 자동 주입
# 앱 코드에서 활용 가능
# Node.js 예제 - 리전 인식 코드
cat <<'EOF' > server.js
const express = require('express');
const app = express();
// Fly.io가 주입하는 환경 변수
const region = process.env.FLY_REGION || 'unknown';
const instanceId = process.env.FLY_ALLOC_ID || 'local';
app.get('/', (req, res) => {
res.json({
message: 'Hello from Fly.io!',
region: region,
instance: instanceId,
timestamp: new Date().toISOString()
});
});
app.get('/health', (req, res) => {
res.status(200).json({ status: 'healthy', region });
});
// 리전별 데이터 처리
app.get('/nearest', (req, res) => {
// 사용자는 자동으로 가장 가까운 리전으로 라우팅됨
res.json({
message: `Served from ${region}`,
latency: 'minimal'
});
});
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`Server running in ${region} on port ${port}`);
});
EOF
# 4. Fly Replay - 요청을 다른 리전으로 리플레이
# 헤더로 특정 리전 강제 지정
curl -H "fly-replay: region=nrt" https://my-app.fly.dev/
# 앱 코드에서 리플레이 응답
# res.setHeader('fly-replay', 'region=nrt');
# 5. Fly Postgres 글로벌 분산
fly postgres create --name my-global-db
fly postgres attach my-global-db
# 읽기 전용 복제본 추가
fly volumes create pg_data --region sin --size 10
fly machine clone <primary-machine-id> --region sin
# 애플리케이션에서 읽기/쓰기 분리
# PRIMARY: fly-replay 헤더로 primary 리전으로 라우팅
# REPLICA: 로컬 리전 복제본에서 읽기
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free