동적 호스트 볼륨 사용
동적 호스트 볼륨 사용 (Use dynamic host volumes)
이 페이지는 동적 호스트 볼륨(dynamic host volume)을 만들고 구성하며 애플리케이션 데이터를 유지하는 데 사용하는 방법을 설명해요.
출처: 문서
본문
소개 (Introduction)
Nomad 동적 호스트 볼륨은 구성 변경을 적용하기 위해 Nomad 노드를 재시작하지 않고도 상태 저장 워크로드의 스토리지를 관리해요. 자원을 지정하는 워크로드에 구애받지 않는(workload-agnostic) 방법을 제공하며 exec, java, docker 작업 드라이버와 함께 작동해요. CLI 또는 API로 동적 호스트 볼륨을 만든 다음 작업 명세서의 volume과 volume_mount 블록으로 작업을 구성해요.
동적 호스트 볼륨 지정에 대한 자세한 내용은 동적 호스트 볼륨 명세를 참조해요.
요구 사항 (Requirements)
Docker 작업 드라이버가 활성화된 Nomad 클러스터 v1.10.0 이상.
볼륨 명세 만들기 (Create the volume specification)
volume.hcl이라는 이름의 파일을 만들고 다음 내용을 추가한 후 저장해요.
volume.hcl
name = "example"
type = "host"
# mkdir is the default built-in plugin
plugin_id = "mkdir"
# allows mounting by only one allocation at a time
capability {
access_mode = "single-node-single-writer"
attachment_mode = "file-system"
}
볼륨을 만들어요.
==> Created host volume example with ID 02eb1d8e-945e-50ee-7640-68b92f622870
✓ Host volume "02eb1d8e" ready
2025-01-21T14:56:35-05:00
ID = 02eb1d8e-945e-50ee-7640-68b92f622870
Name = example
Namespace = default
Plugin ID = mkdir
Node ID = d87c86d7-d22b-f811-c329-09e263995e86
Node Pool = default
Capacity = 0 B
State = ready
Host Path = /run/nomad/dev/alloc_mounts/02eb1d8e-945e-50ee-7640-68b92f622870
출력의 노드 ID로 볼륨이 노드에 지문(fingerprint) 처리됐는지 확인해요.
...
Host Volumes
Name ReadOnly Source
example false /run/nomad/dev/alloc_mounts/02eb1d8e-945e-50ee-7640-68b92f622870
...
볼륨 ID를 환경 변수로 설정해요.
작업 만들고 실행 (Create and run the job)
다음 작업 명세서는 동적 호스트 볼륨 명세에서 example이라는 이름의 볼륨을 마운트해요.
example.nomad.hcl이라는 이름의 파일을 만들고 다음 내용을 추가한 후 저장해요.
example.nomad.hcl
group "group" {
# claim the dynamic host volume for the allocation
volume "groupvol" {
type = "host"
source = "example"
access_mode = "single-node-single-writer"
attachment_mode = "file-system"
}
network {
port "www" {
to = 8001
}
}
task "task" {
driver = "docker"
config {
image = "busybox:1"
command = "httpd"
args = ["-vv", "-f", "-p", "8001", "-h", "/srv"]
ports = ["www"]
}
# mount the claimed volume to the task
volume_mount {
volume = "groupvol"
destination = "/srv"
}
}
}
}
작업을 실행해요.
호스트 볼륨과 상호작용 (Interact with the host volume)
작업의 Allocation ID를 ALLOC_ID라는 이름의 환경 변수로 내보내요.
할당에서 셸 세션을 엽니다.
할당의 셸 프롬프트에서 마운트된 볼륨에 파일을 써요.
할당의 셸 세션을 종료해요.
할당에서 실행 중인 HTTP 서버의 주소를 얻어요.
...
Allocation Addresses (mode = "bridge"):
Label Dynamic Address
*www yes 192.168.1.160:26512 -> 8001
웹 브라우저에서 주소를 열거나 curl 같은 도구를 사용해 변경 사항을 확인해요.
<html>hello, world</html>
할당 재스케줄 (Reschedule the allocation)
할당을 중지해 Nomad가 재스케줄링하도록 강제해요.
대체 할당에서 셸 세션을 엽니다.
할당의 셸 프롬프트에서 이전에 마운트된 볼륨에 쓴 파일을 읽어요.
<html>hello, world</html>
할당의 셸 세션을 종료해요.
정리 (Clean up)
example 작업을 중지해요.
동적 호스트 볼륨을 삭제해요.
다음 단계 (Next steps)
동적 호스트 볼륨과 관련 개념에 대한 자세한 내용은 다음 자료를 참조해요.