DEV Community

Cover image for 디지털오션 API 사용법: 개발자를 위한 클라우드 인프라 가이드
Rihpig
Rihpig

Posted on • Originally published at apidog.com

디지털오션 API 사용법: 개발자를 위한 클라우드 인프라 가이드

요약 (TL;DR)

DigitalOcean API를 활용하면 드롭렛, 볼륨, 방화벽, 로드 밸런서, Kubernetes 클러스터 등 주요 인프라를 코드로 즉시 관리할 수 있습니다. 인증은 개인 접근 토큰으로 진행하며, 엔드포인트는 api.digitalocean.com/v2입니다. 요율 제한에 유의해야 하며, 인프라 자동화 및 검증에는 Apidog로 테스트와 문서화를 병행하세요.

지금 Apidog를 체험해보세요

소개

DigitalOcean은 필수 클라우드 인프라에 집중하여 복잡도를 최소화합니다. AWS/GCP처럼 수백 가지 옵션을 제공하지 않고, 컴퓨팅(드롭렛), 스토리지(볼륨), 네트워킹(유동 IP, 방화벽), 관리형 Kubernetes, 앱 플랫폼 등 실용적인 핵심 서비스만 제공합니다. API 또한 단순하며 빠르게 자동화가 가능합니다.

실무 개발자들이 DigitalOcean API를 사용하는 주요 시나리오:

  • 개발 환경 자동화 및 생성
  • Kubernetes 클러스터 및 노드 관리
  • Terraform/Pulumi 기반 코드형 인프라 적용
  • CI/CD 파이프라인 프로비저닝
  • 멀티 리전 배포 자동화

💡 인프라 자동화 시 Apidog는 API 호출 테스트, 템플릿화, 팀 협업에 효율적입니다.

인증

개인 접근 토큰

  1. DigitalOcean 대시보드 → API → 새 토큰 생성.
  2. 토큰 이름/만료일 지정 후 발급.
  3. 토큰은 안전하게 저장.

토큰 사용 예시:

curl -X GET "https://api.digitalocean.com/v2/account" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

응답 형식

{
  "account": {
    "droplet_limit": 25,
    "email": "you@example.com",
    "name": "Your Name",
    "uuid": "abc123xyz",
    "email_verified": true,
    "status": "active"
  }
}
Enter fullscreen mode Exit fullscreen mode

드롭렛 (가상 머신)

모든 드롭렛 나열

curl -X GET "https://api.digitalocean.com/v2/droplets" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

드롭렛 생성

curl -X POST "https://api.digitalocean.com/v2/droplets" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-droplet",
    "region": "nyc1",
    "size": "s-2vcpu-4gb",
    "image": "ubuntu-20-04-x64",
    "ssh_keys": ["ssh-rsa AAAA..."],
    "backups": false,
    "ipv6": true,
    "tags": ["web", "production"]
  }'
Enter fullscreen mode Exit fullscreen mode

주요 크기:

  • s-1vcpu-1gb: 1 vCPU, 1GB RAM (월 5달러)
  • s-2vcpu-2gb: 2 vCPU, 2GB RAM (월 10달러)
  • s-2vcpu-4gb: 2 vCPU, 4GB RAM (월 20달러)
  • s-4vcpu-8gb: 4 vCPU, 8GB RAM (월 40달러)

주요 리전:

  • nyc1, nyc3 (뉴욕)
  • sfo3 (샌프란시스코)
  • ams3 (암스테르담)
  • sgp1 (싱가포르)

드롭렛 세부 정보 가져오기

curl -X GET "https://api.digitalocean.com/v2/droplets/DROPLET_ID" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

드롭렛 삭제

curl -X DELETE "https://api.digitalocean.com/v2/droplets/DROPLET_ID" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

드롭렛 작업

재부팅:

curl -X POST "https://api.digitalocean.com/v2/droplets/DROPLET_ID/actions" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "reboot"
  }'
Enter fullscreen mode Exit fullscreen mode

크기 조정:

curl -X POST "https://api.digitalocean.com/v2/droplets/DROPLET_ID/actions" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "resize",
    "size": "s-4vcpu-8gb"
  }'
Enter fullscreen mode Exit fullscreen mode

스냅샷:

curl -X POST "https://api.digitalocean.com/v2/droplets/DROPLET_ID/actions" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "snapshot",
    "name": "my-snapshot"
  }'
Enter fullscreen mode Exit fullscreen mode

볼륨 (블록 스토리지)

볼륨 생성

curl -X POST "https://api.digitalocean.com/v2/volumes" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "size_gigabytes": 100,
    "name": "my-volume",
    "region": "nyc1",
    "description": "Data volume for web servers"
  }'
Enter fullscreen mode Exit fullscreen mode

드롭렛에 볼륨 연결

curl -X POST "https://api.digitalocean.com/v2/volumes/VOLUME_ID/actions" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "attach",
    "droplet_id": DROPLET_ID
  }'
Enter fullscreen mode Exit fullscreen mode

볼륨 나열

curl -X GET "https://api.digitalocean.com/v2/volumes" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

네트워킹

유동 IP 나열

curl -X GET "https://api.digitalocean.com/v2/floating_ips" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

유동 IP 할당

curl -X POST "https://api.digitalocean.com/v2/floating_ips" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "droplet_id": DROPLET_ID,
    "region": "nyc1"
  }'
Enter fullscreen mode Exit fullscreen mode

방화벽 생성

curl -X POST "https://api.digitalocean.com/v2/firewalls" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "web-firewall",
    "inbound_rules": [
      {
        "protocol": "tcp",
        "ports": "80",
        "sources": {
          "addresses": ["0.0.0.0/0"]
        }
      },
      {
        "protocol": "tcp",
        "ports": "443",
        "sources": {
          "addresses": ["0.0.0.0/0"]
        }
      },
      {
        "protocol": "tcp",
        "ports": "22",
        "sources": {
          "addresses": ["your-ip/32"]
        }
      }
    ],
    "outbound_rules": [
      {
        "protocol": "tcp",
        "ports": "80",
        "destinations": {
          "addresses": ["0.0.0.0/0"]
        }
      }
    ],
    "droplet_ids": [DROPLET_ID]
  }'
Enter fullscreen mode Exit fullscreen mode

로드 밸런서

로드 밸런서 생성

curl -X POST "https://api.digitalocean.com/v2/load_balancers" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-lb",
    "region": "nyc1",
    "algorithm": "round_robin",
    "health_check": {
      "protocol": "http",
      "port": 80,
      "path": "/",
      "check_interval_seconds": 10,
      "response_timeout_seconds": 5,
      "healthy_threshold": 3,
      "unhealthy_threshold": 3
    },
    "forwarding_rules": [
      {
        "entry_protocol": "http",
        "entry_port": 80,
        "target_protocol": "http",
        "target_port": 80
      },
      {
        "entry_protocol": "https",
        "entry_port": 443,
        "target_protocol": "https",
        "target_port": 443,
        "tls_passthrough": true
      }
    ],
    "droplet_ids": [DROPLET_ID_1, DROPLET_ID_2]
  }'
Enter fullscreen mode Exit fullscreen mode

Kubernetes 클러스터

Kubernetes 클러스터 생성

curl -X POST "https://api.digitalocean.com/v2/kubernetes/clusters" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-cluster",
    "region": "nyc1",
    "version": "1.28",
    "node_pools": [
      {
        "name": "worker-pool",
        "size": "s-2vcpu-4gb",
        "count": 3,
        "auto_scale": true,
        "min_nodes": 2,
        "max_nodes": 6
      }
    ]
  }'
Enter fullscreen mode Exit fullscreen mode

노드 풀 나열

curl -X GET "https://api.digitalocean.com/v2/kubernetes/clusters/CLUSTER_ID/node_pools" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

노드 풀 확장

curl -X PUT "https://api.digitalocean.com/v2/kubernetes/clusters/CLUSTER_ID/node_pools/POOL_ID" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "count": 5
  }'
Enter fullscreen mode Exit fullscreen mode

클러스터 삭제

curl -X DELETE "https://api.digitalocean.com/v2/kubernetes/clusters/CLUSTER_ID" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

Apidog로 테스트하기

인프라 자원은 비용이 크므로, 실제 리소스 생성 전에 테스트와 유효성 검사가 필수입니다.

Apidog를 사용하여 DigitalOcean API 테스트

1. 환경 설정

DIGITALOCEAN_TOKEN: your_token
BASE_URL: https://api.digitalocean.com/v2
DEFAULT_REGION: nyc1
DEFAULT_SIZE: s-2vcpu-4gb
Enter fullscreen mode Exit fullscreen mode

2. 응답 유효성 검사

pm.test('Droplet created successfully', () => {
  const response = pm.response.json()
  pm.expect(response.droplet).to.have.property('id')
  pm.expect(response.droplet.status).to.eql('new')
})

pm.test('Token is valid', () => {
  const response = pm.response.json()
  pm.expect(response.account).to.exist
  pm.expect(response.account.status).to.eql('active')
})
Enter fullscreen mode Exit fullscreen mode

3. 드라이 런 개념

DigitalOcean은 공식 드라이 런 기능이 없으나, 입력값 유효성 검증을 통해 사전 체크가 가능합니다.

const validRegions = ['nyc1', 'sfo3', 'ams3', 'sgp1']
const validSizes = ['s-1vcpu-1gb', 's-2vcpu-2gb', 's-2vcpu-4gb']

pm.test('Region is valid', () => {
  const requestBody = JSON.parse(pm.request.body.raw)
  pm.expect(validRegions).to.include(requestBody.region)
})

pm.test('Size is valid', () => {
  const requestBody = JSON.parse(pm.request.body.raw)
  pm.expect(validSizes).to.include(requestBody.size)
})
Enter fullscreen mode Exit fullscreen mode

Apidog로 DigitalOcean 인프라 API를 무료로 손쉽게 테스트할 수 있습니다.

일반적인 오류 및 수정

401 권한 없음

  • 원인: 토큰 오류/만료
  • 해결: 대시보드에서 토큰 재생성, Authorization 헤더 형식 점검

422 처리할 수 없는 엔티티

  • 원인: 잘못된 매개변수(리전/크기/이미지 등)
  • 해결: 공식 문서에서 유효값 확인
    • 지원하지 않는 리전/크기
    • 존재하지 않는 이미지 ID
    • 드롭렛 제한 초과

429 너무 많은 요청

  • 원인: 요율 제한(기본 시간당 2000)
  • 해결: 백오프(backoff) 로직 적용
async function doRequest(url, options, retries = 3) {
  for (let i = 0; i < retries; i++) {
    const response = await fetch(url, options)
    if (response.status === 429) {
      await sleep(Math.pow(2, i) * 1000)
      continue
    }
    return response
  }
  throw new Error('Rate limited')
}
Enter fullscreen mode Exit fullscreen mode

드롭렛 제한에 도달함

  • 원인: 계정 한도 초과
  • 해결: 미사용 드롭렛 삭제 또는 지원팀에 한도 상향 요청

대안 및 비교

기능 DigitalOcean AWS GCP
드롭렛 크기 고정 사용자 정의 사용자 정의
Kubernetes 관리형 DOKS EKS GKE
객체 스토리지 Spaces S3 Cloud Storage
블록 스토리지 Volumes EBS Persistent Disk
로드 밸런서 내장 ELB Cloud Load Balancing
무료 티어 200달러 크레딧 제한적 300달러 크레딧
API 단순성 ★★★★★ ★★☆☆☆ ★★★☆☆

DigitalOcean은 단순성에서 강점을 가지며, 중첩된 서비스 없이 직관적인 API로 대부분의 작업을 빠르게 자동화할 수 있습니다.

실제 사용 사례

개발 환경 자동화

브랜치별로 격리된 개발 환경을 API로 자동 생성. PR마다 최신 코드로 드롭렛을 프로비저닝하고, 병합 시 자동 삭제. 수동 설정 없이 실제 프로덕션과 유사한 환경에서 테스트 가능.

자동 스케일링 웹 서버

애플리케이션이 CPU 부하를 모니터링하여 70% 초과 시 API로 새로운 드롭렛 생성 및 로드 밸런서 추가. 부하 감소 시 드롭렛 자동 파괴. 고성능과 비용 효율을 동시 달성.

데이터베이스 클러스터 자동화

관리형 데이터베이스 서비스에서 복제본 볼륨, 백업, 페일오버 등 구성을 API로 자동화.

결론

이 글에서 다룬 핵심 요약:

  • 개인 토큰 기반 인증
  • 드롭렛 생성/관리 자동화
  • 볼륨(블록 스토리지) 활용
  • 방화벽/로드 밸런서 구성
  • Kubernetes 클러스터 및 노드 풀 관리
  • Apidog로 인프라 사전 테스트

자주 묻는 질문 (FAQ)

드롭렛 비용은 얼마인가요?

1 vCPU/1GB 기준 월 5달러부터. 최신 요금은 가격 페이지 참고. 시간당 청구도 지원.

API로 생성된 드롭렛에 SSH 키를 사용할 수 있나요?

예. 생성 요청 시 ssh_keys 배열에 SSH 키 지문을 포함하면 됩니다.

볼륨과 Spaces 차이점은?

볼륨: 드롭렛에 연결하는 블록 스토리지.

Spaces: S3와 유사한 객체 스토리지.

DB는 볼륨, 파일은 Spaces 권장.

Kubernetes 구성을 어떻게 가져오나요?

curl -X GET "https://api.digitalocean.com/v2/kubernetes/clusters/CLUSTER_ID/kubeconfig" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

드롭렛 크기를 조정할 수 있나요?

가능. 크기 조정 작업을 활용하세요. 다운그레이드는 전원 오프 필요, 업그레이드는 실행 중에도 지원.

백업과 스냅샷 차이점은?

백업: 자동 주간/일별 복사본(관리형).

스냅샷: 수동 주문형 이미지(직접 생성).

드롭렛 생성에는 얼마나 걸리나요?

일반적으로 30~60초. 리전/사이즈에 따라 다를 수 있음.

Terraform과 연동 가능한가요?

네. DigitalOcean은 공식 Terraform provider를 제공합니다. IaC에 적극 활용하세요.

Top comments (0)