본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Devmapper 스냅샷터

원문 보기 위키 갱신

Devmapper 스냅샷터 (Devmapper snapshotter)

Devmapper는 Device-mapper thin-pool 안의 파일시스템 이미지에 스냅샷을 저장하는 containerd 스냅샷터 플러그인이에요. 이 플러그인은 device snapshot support 같은 Device-mapper 기능을 활용하죠. 이 문서는 thin-pool 준비 방법, 설정 플래그, 개발 환경과 프로덕션 환경 각각의 thin-pool 구성 방법을 다뤄요.

출처: 문서

본문

설정 (Setup)

devmapper 스냅샷터 플러그인을 쓰려면 Device-mapper thin-pool을 미리 준비하고 containerd 설정 파일을 업데이트해야 해요. 이 파일은 보통 /etc/containerd/config.toml에 있어요.

설정 파일에 넣을 수 있는 최소 예시 항목은 이래요:

version = 2

[plugins]
  ...
  [plugins."io.containerd.snapshotter.v1.devmapper"]
    root_path = "/var/lib/containerd/devmapper"
    pool_name = "containerd-pool"
    base_image_size = "8192MB"
  ...

지원되는 설정 플래그는 다음과 같아요:

플래그 설명
root_path 메타데이터가 놓일 디렉터리예요(비워 두면 containerd 플러그인의 기본 위치를 써요)
pool_name Device-mapper thin-pool에 쓸 이름이에요. 풀 이름은 /dev/mapper/ 디렉터리의 이름과 같아야 해요
base_image_size 베이스(풀) 디바이스에서 thin device 스냅샷을 만들 때 할당할 공간 크기를 정의해요
async_remove 스냅샷 GC의 cleanup 콜백으로 디바이스를 비동기 제거하는 플래그예요 (기본값: false)
discard_blocks 디바이스를 제거할 때 블록을 discard할지 여부예요. 루프백 디바이스를 쓸 때 파일시스템에 디스크 공간을 돌려주는 데 특히 유용해요. (기본값: false)
fs_type 스냅샷 디바이스 마운트에 쓸 파일시스템을 정의해요. 유효한 값은 ext4와 xfs예요 (기본값: "ext4")
fs_options 선택적으로 파일시스템 옵션을 정의해요. 현재는 ext4 파일시스템에만 적용돼요. (기본값: "")

root_path, pool_name, base_image_size는 필수 스냅샷터 파라미터예요.

실행 (Run)

다음 명령으로 직접 사용해 보세요:

ctr images pull --snapshotter devmapper docker.io/library/hello-world:latest
ctr run --snapshotter devmapper docker.io/library/hello-world:latest test

요구 사항 (Requirements)

devicemapper 스냅샷터를 쓰려면 dmsetup(>= 1.02.110) 명령줄 도구가 설치되어 있고 사용 가능해야 해요. Ubuntu에서는 apt-get install dmsetup 명령으로 설치할 수 있어요.

Device-Mapper thin-pool 설정 방법

요구 사항, 디스크 구성, 환경에 따라 Device-mapper thin-pool을 구성하는 방법은 여러 가지예요. 아래에 개발 환경용과 프로덕션 환경용, 흔히 쓰이는 두 가지 구성을 소개해요.

1. 루프백 디바이스 (Loopback Devices)

로컬 개발 환경에서는 루프백 디바이스를 활용할 수 있어요. 이런 구성은 간단하고 개발과 테스트에 잘 맞아요(이 구성은 느리고 프로덕션 용도로는 권장되지 않는다는 점을 유의하세요). 다음 스크립트를 실행하면 관련 메타데이터와 데이터 디바이스 파일을 갖춘 thin-pool 디바이스를 만들어요:

#!/bin/bash
set -ex

DATA_DIR=/var/lib/containerd/devmapper
POOL_NAME=devpool

sudo mkdir -p ${DATA_DIR}

# Create data file
sudo touch "${DATA_DIR}/data"
sudo truncate -s 100G "${DATA_DIR}/data"

# Create metadata file
sudo touch "${DATA_DIR}/meta"
sudo truncate -s 10G "${DATA_DIR}/meta"

# Allocate loop devices
DATA_DEV=$(sudo losetup --find --show "${DATA_DIR}/data")
META_DEV=$(sudo losetup --find --show "${DATA_DIR}/meta")

# Define thin-pool parameters.
# See https://www.kernel.org/doc/Documentation/device-mapper/thin-provisioning.txt for details.
SECTOR_SIZE=512
DATA_SIZE="$(sudo blockdev --getsize64 -q ${DATA_DEV})"
LENGTH_IN_SECTORS=$(bc <<< "${DATA_SIZE}/${SECTOR_SIZE}")
DATA_BLOCK_SIZE=128
LOW_WATER_MARK=32768

# Create a thin-pool device
sudo dmsetup create "${POOL_NAME}" \
    --table "0 ${LENGTH_IN_SECTORS} thin-pool ${META_DEV} ${DATA_DEV} ${DATA_BLOCK_SIZE} ${LOW_WATER_MARK}"

cat << EOF
#
# Add this to your config.toml configuration file and restart the containerd daemon
#
[plugins]
  [plugins."io.containerd.snapshotter.v1.devmapper"]
    pool_name = "${POOL_NAME}"
    root_path = "${DATA_DIR}"
    base_image_size = "10GB"
    discard_blocks = true
EOF

dmsetup으로 thin-pool이 성공적으로 만들어졌는지 확인해요:

sudo dmsetup ls
devpool	(253:0)

containerd가 설정되고 재시작되면 다음 출력을 볼 거예요:

INFO[2020-03-17T20:24:45.532604888Z] loading plugin "io.containerd.snapshotter.v1.devmapper"...  type=io.containerd.snapshotter.v1
INFO[2020-03-17T20:24:45.532672738Z] initializing pool device "devpool"
2. direct-lvm thin-pool

thin-pool을 설정하는 또 다른 방법은 container-storage-setup 도구(예전 이름 docker-storage-setup)를 쓰는 거예요. devicemapper 같은 CoW 파일시스템을 구성하는 스크립트예요:

#!/bin/bash
set -ex

# Block device to use for devmapper thin-pool
BLOCK_DEV=/dev/sdf
POOL_NAME=devpool
VG_NAME=containerd

# Install container-storage-setup tool
git clone https://github.com/projectatomic/container-storage-setup.git
cd container-storage-setup/
sudo make install-core
echo "Using version $(container-storage-setup -v)"

# Create configuration file
# Refer to `man container-storage-setup` to see available options
sudo tee /etc/sysconfig/docker-storage-setup <<EOF
DEVS=${BLOCK_DEV}
VG=${VG_NAME}
CONTAINER_THINPOOL=${POOL_NAME}
EOF

# Run the script
sudo container-storage-setup

cat << EOF
#
# Add this to your config.toml configuration file and restart containerd daemon
#
[plugins]
  [plugins.devmapper]
    root_path = "/var/lib/containerd/devmapper"
    pool_name = "${VG_NAME}-${POOL_NAME}"
    base_image_size = "10GB"
EOF

성공하면 container-storage-setup이 이런 출력을 내놓아요:

+ echo VG=containerd
+ sudo container-storage-setup
INFO: Volume group backing root filesystem could not be determined
INFO: Writing zeros to first 4MB of device /dev/xvdf
4+0 records in
4+0 records out
4194304 bytes (4.2 MB) copied, 0.0162906 s, 257 MB/s
INFO: Device node /dev/xvdf1 exists.
  Physical volume "/dev/xvdf1" successfully created.
  Volume group "containerd" successfully created
  Rounding up size to full physical extent 12.00 MiB
  Thin pool volume with chunk size 512.00 KiB can address at most 126.50 TiB of data.
  Logical volume "devpool" created.
  Logical volume containerd/devpool changed.
...

그리고 dmsetup은 다음 출력을 내놓아요:

sudo dmsetup ls
containerd-devpool          (253:2)
containerd-devpool_tdata    (253:1)
containerd-devpool_tmeta    (253:0)

프로덕션 devmapper 설정에 대한 추가 정보는 프로덕션용 direct-lvm 모드 구성도 참고하세요.

추가 자료 (Additional Resources)

Device-mapper, thin provisioning 등에 대해 더 알고 싶다면 다음 자료를 참고하세요:

더 알아보기 (Learn more)