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

containerd 레지스트리 설정 — 개념과 hosts.toml

원문 보기 위키 갱신

containerd v1.5부터 ctr 클라이언트, containerd 이미지 서비스 클라이언트, 그리고 kubectl이나 crictl 같은 CRI 클라이언트를 위해 새로운 레지스트리 호스트 설정 방식이 도입됐어요. 핵심은 설정 디렉터리 아래에 레지스트리별로 hosts.toml 파일을 두는 방식이고, 이 문서는 개념 설명과 실전 예제, hosts.toml 필드 상세 설명까지 모두 다룹니다.

출처: 문서

본문

레지스트리 설정 소개

containerd v1.5에서 ctr 클라이언트(관리자/개발자용 containerd 도구), containerd 이미지 서비스 클라이언트, 그리고 kubectl과 crictl 같은 CRI 클라이언트를 위해 새로운 레지스트리 호스트 설정 지원이 구현됐어요.

이 클라이언트들에 대해 레지스트리를 설정하려면, 설정 디렉터리 안에 원하는 레지스트리 호스트마다 hosts.toml 파일을 지정(선택 사항)하면 됩니다.

참고: 이 디렉터리 아래의 변경 사항은 containerd 데몬 재시작이 필요 없어요.

레지스트리 API 지원

설정된 모든 레지스트리 호스트는 OCI Distribution Specification을 준수해야 해요. 준수하지 않거나 비표준 동작을 구현한 레지스트리는 지원을 보장하지 않으며, 릴리스 사이에서 갑자기 깨질 수 있습니다.

현재 지원되는 OCI Distribution 버전: v1.0.0

설정 디렉터리 지정하기

CTR에서 호스트 네임스페이스 설정 사용하기

ctr로 컨테이너 이미지를 pull할 때 --hosts-dir 옵션을 쓰면, 지정한 경로에 있는 호스트 설정 파일을 찾아 사용하라고 알려 줄 수 있어요.

ctr images pull --hosts-dir "/etc/containerd/certs.d" myregistry.io:5000/image_name:tag

CRI

레지스트리 미러(registry.mirrors)와 registry.configs를 지정하던 기존 CRI 설정 방식은 지원 중단(DEPRECATED) 됐어요. 이제 레지스트리 config_path를 hosts.toml 파일들이 있는 경로로 지정해야 합니다.

config.toml(기본 위치: /etc/containerd/config.toml)을 다음처럼 수정하세요.

  • containerd 2.x인 경우
version = 3

[plugins."io.containerd.cri.v1.images".registry]
   config_path = "/etc/containerd/certs.d"
  • containerd 1.x인 경우
version = 2

[plugins."io.containerd.grpc.v1.cri".registry]
   config_path = "/etc/containerd/certs.d"

Docker의 인증서 파일 패턴 지원

호스트 디렉터리에 hosts.toml 설정이 없으면, Docker의 인증서 파일 패턴(CA 인증서는 ".crt" 파일, 클라이언트 인증서는 ".cert"/".key" 파일)에 따라 인증서 파일을 확인하는 방식으로 폴백(fallback)해요.

레지스트리 호스트 네임스페이스

레지스트리 호스트는 컨테이너 이미지와 아티팩트를 가져오는 위치예요. 이 호스트들은 로컬일 수도 원격일 수도 있고, 보통 OCI distribution specification을 따르는 http/https로 접근합니다. 레지스트리 미러는 레지스트리 호스트는 아니지만, 미러 역시 콘텐츠를 pull하는 데 사용될 수 있어요. 레지스트리 호스트는 보통 인터넷 도메인 이름, 즉 레지스트리 호스트 이름으로 불립니다. 예를 들어 docker.io, quay.io, gcr.io, ghcr.io가 있죠.

레지스트리 호스트 네임스페이스는 containerd 레지스트리 설정의 관점에서, 레지스트리 호스트 이름 또는 IP 주소와 선택적인 포트 식별자로 지정되는 hosts.toml 파일의 경로를 말해요. 이미지에 대한 pull 요청의 형식은 보통 다음과 같습니다.

pull [registry_host_name|IP address][:port][/v2][/org_path]<image_name>[:tag|@DIGEST]

레지스트리 호스트 네임스페이스 부분은 [registry_host_name|IP address][:port]예요. docker.io의 예제 트리는 다음과 같습니다.

$ tree /etc/containerd/certs.d
/etc/containerd/certs.d
└── docker.io
    └── hosts.toml

선택적으로, 다른 네임스페이스가 일치하지 않을 때의 폴백으로 _default 레지스트리 호스트 네임스페이스를 사용할 수 있어요.

위 pull 요청 형식에서 /v2 부분은 distribution api의 버전을 가리켜요. pull 요청에 포함되지 않으면, 앞서 링크한 distribution specification을 준수하는 모든 클라이언트는 /v2가 기본으로 추가됩니다.

레지스트리 호스트 네임스페이스와 다른 호스트(예: 미러)가 설정되어 있으면, containerd는 요청에 레지스트리 호스트 네임스페이스를 ns라는 쿼리 파라미터로 덧붙여요.

예를 들어 myregistry.io라는 프라이빗 레지스트리에서 포트 5000으로 image_name:tag_name을 pull한다고 해 볼게요.

pull myregistry.io:5000/image_name:tag_name

이 pull은 https://myregistry.io:5000/v2/image_name/manifests/tag_name으로 해석돼요.

같은 pull에 mymirror.io용 호스트 설정이 있었다면 https://mymirror.io/v2/image_name/manifests/tag_name?ns=myregistry.io:5000으로 해석됩니다.

레지스트리 호스트의 포트 처리

레지스트리 호스트에 포트가 포함되어 있다면(예: myregistry.io:5000), containerd는 hosts 설정 디렉터리 아래에서 다음 순서의 레지스트리 호스트 네임스페이스에서 hosts.toml 파일을 찾아요.

  • Unix의 경우
myregistry.io_5000_
myregistry.io:5000
_default
  • Windows의 경우(디렉터리/파일 이름에 :를 지원하지 않음)
myregistry.io_5000_
myregistry.io5000
_default

레지스트리 자격 증명 지정하기

CTR

ctr로 이미지 작업을 수행할 때는 --help 옵션으로 자격 증명 지정에 쓸 수 있는 옵션 목록을 확인할 수 있어요.

ctr i pull --help
...
OPTIONS:
   --skip-verify, -k                 skip SSL certificate validation
   --plain-http                      allow connections using plain HTTP
   --user value, -u value            user[:password] Registry user and password
   --refresh value                   refresh token for authorization server
   --hosts-dir value                 Custom hosts configuration directory
   --tlscacert value                 path to TLS root CA
   --tlscert value                   path to TLS client certificate
   --tlskey value                    path to TLS client key
   --http-dump                       dump all HTTP request/responses when interacting with container registry
   --http-trace                      enable HTTP tracing for registry interactions
   --snapshotter value               snapshotter name. Empty value stands for the default value. [$CONTAINERD_SNAPSHOTTER]
   --label value                     labels to attach to the image
   --platform value                  Pull content from a specific platform
   --all-platforms                   pull content and metadata from all platforms
   --all-metadata                    Pull metadata for all platforms
   --print-chainid                   Print the resulting image's chain ID
   --max-concurrent-downloads value  Set the max concurrent downloads for each pull (default: 0)

CRI

레지스트리 미러(registry.mirrors)와 registry.configs를 지정하던 기존 CRI 설정 방식은 지원 중단됐지만, 여전히 CRI config를 통해 자격 증명을 지정할 수 있어요.

추가로 containerd CRI 플러그인은 CRI pull 이미지 서비스 요청으로 전달되는 인증 파라미터도 구현/지원해요. 예를 들어 containerd가 Kubernetes의 컨테이너 런타임 구현체일 때, containerd CRI 플러그인은 kubelet이 Kubernetes Image Pull Secrets에서 가져온 인증 자격 증명을 받습니다.

레지스트리 설정 — 예제

Docker를 위한 간단한(기본) 호스트 설정

기본 레지스트리 호스트 설정의 간단한 예제예요. containerd 설정인 config.toml에 config_path = "/etc/containerd/certs.d"를 지정하고, 설정 경로에 호스트 네임스페이스를 나타내는 docker.io 디렉터리를 만든 다음, 그 docker.io 안에 호스트 네임스페이스를 구성하는 hosts.toml 파일을 추가하세요. 다음과 같은 모습이 됩니다.

$ tree /etc/containerd/certs.d
/etc/containerd/certs.d
└── docker.io
    └── hosts.toml

$ cat /etc/containerd/certs.d/docker.io/hosts.toml
server = "https://docker.io"

[host."https://registry-1.docker.io"]
  capabilities = ["pull", "resolve"]

Docker용 로컬 미러 설정하기

server = "https://registry-1.docker.io"    # Exclude this to not use upstream

[host."https://public-mirror.example.com"]
  capabilities = ["pull"]                  # Requires less trust, won't resolve tag to digest from this host
[host."https://docker-mirror.internal"]
  capabilities = ["pull", "resolve"]
  ca = "docker-mirror.crt"                 # Or absolute path /etc/containerd/certs.d/docker.io/docker-mirror.crt

모든 레지스트리용 기본 미러 설정하기

의도한 레지스트리와 상관없이 미러를 사용하는 예제예요. 정의된 모든 호스트를 시도한 후에는 업스트림 레지스트리가 자동으로 사용됩니다.

$ tree /etc/containerd/certs.d
/etc/containerd/certs.d
└── _default
    └── hosts.toml

$ cat /etc/containerd/certs.d/_default/hosts.toml
[host."https://registry.example.com"]
  capabilities = ["pull", "resolve"]

미러 만 사용하고 업스트림은 조회하지 않도록 확실히 하고 싶다면, 호스트가 아니라 server로 미러를 지정하세요. 다른 미러를 먼저 사용하고 싶다면 추가 호스트를 지정할 수도 있어요.

$ cat /etc/containerd/certs.d/_default/hosts.toml
server = "https://registry.example.com"

TLS 검증 우회 예제

192.168.31.250:5000 프라이빗 레지스트리에 대한 TLS 검증을 우회하려면

"/etc/containerd/certs.d/docker.io/hosts.toml" 경로에 다음과 비슷한 내용의 hosts.toml을 만들어 주세요.

server = "https://registry-1.docker.io"

[host."http://192.168.31.250:5000"]
  capabilities = ["pull", "resolve", "push"]
  skip_verify = true

hosts.toml 내용 상세 설명

레지스트리 config_path 아래의 각 레지스트리 호스트 네임스페이스 디렉터리에는 hosts.toml 설정 파일을 둘 수 있어요. 다음의 루트 수준 toml 필드들이 해당 레지스트리 호스트 네임스페이스에 적용됩니다.

참고: hosts.toml 파일에 지정하는 모든 경로는 절대 경로이거나 hosts.toml 파일 기준의 상대 경로일 수 있어요.

server 필드

server는 이 레지스트리 호스트 네임스페이스의 기본 서버를 지정해요.

host(들)가 지정되면 나열된 순서대로 호스트를 먼저 시도하고, 모든 host(들)가 시도된 뒤에 server가 폴백으로 사용됩니다.

server가 지정되지 않으면 이미지의 레지스트리 호스트 네임스페이스가 자동으로 사용돼요.

server = "https://docker.io"

capabilities 필드

capabilities는 호스트가 수행할 수 있는 작업을 지정하는 선택적 설정이에요. 해당하는 값만 포함하면 됩니다.

capabilities =  ["pull", "resolve", "push"]

capabilities(또는 호스트 capabilities)는 레지스트리 호스트의 능력을 나타내요. 이는 레지스트리 호스트가 수행해도 신뢰할 수 있는 작업의 집합이기도 합니다.

예를 들어 push는 업스트림 원본에서만 수행해야 하는 능력이지, 미러에서 수행해서는 안 돼요.

resolve(이름을 다이제스트로 변환하는 과정)는 신뢰할 수 있는 작업으로 취급되어야 하고, 신뢰할 수 있는 호스트(더 좋게는 매핑의 출처를 증명할 수 있는 안전한 프로세스)만 수행해야 합니다. 공개 미러는 resolve 동작을 수행한다고 신뢰해서는 안 돼요.

레지스트리 유형 Pull Resolve Push
공개 레지스트리 yes yes yes
프라이빗 레지스트리 yes yes yes
공개 미러 yes no no
프라이빗 미러 yes yes no

ca 필드

ca(Certificate Authority Certification)는 레지스트리 네임스페이스 인증에 사용할 ca 파일을 가리키는 경로 하나 또는 경로 배열로 설정할 수 있어요.

ca = "/etc/certs/mirror.pem"

또는

ca = ["/etc/certs/test-1-ca.pem", "/etc/certs/special.pem"]

client 필드

client 인증서는 다음처럼 설정해요.

경로 하나:

client = "/etc/certs/client.pem"

경로 배열:

client = ["/etc/certs/client-1.pem", "/etc/certs/client-2.pem"]

경로 쌍의 배열:

client = [["/etc/certs/client.cert", "/etc/certs/client.key"],["/etc/certs/client.pem", ""]]

skip_verify 필드

skip_verify를 true로 설정하면 레지스트리의 인증서 체인과 호스트 이름 검증을 건너뛰어요. 이는 테스트 목적이나 다른 연결 검증 방법과 조합할 때만 사용해야 합니다. (기본값은 false)

skip_verify = false

header 필드 (toml 테이블 형식)

[header]에는 문자열 하나 또는 문자열 배열에 대응하는 키를 여러 개 담을 수 있어요.

[header]
  x-custom-1 = "custom header"

또는

[header]
  x-custom-1 = ["custom header part a","part b"]

또는

[header]
  x-custom-1 = "custom header"
  x-custom-1-2 = "another custom header"

override_path 필드

override_path는 호스트의 API 루트 엔드포인트가 API 스펙이 아니라 URL 경로로 정의된다는 것을 나타내요. /v2 접두사가 없는 OCI 비준수 레지스트리에 사용할 수 있습니다. (기본값은 false)

override_path = true

dial_timeout 필드

dial_timeout은 연결 시도가 완료되기까지 허용되는 최대 시간을 지정해요. 미러에 접근할 수 없을 때 원본 레지스트리로 폴백하는 지연을 줄이는 데 짧은 타임아웃이 도움이 됩니다. (기본값은 30s)

dial_timeout = "1s"

host 필드(들) (toml 테이블 형식)

hosts.toml 설정의 [host]."https://namespace"와 [host]."http://namespace" 항목은 기본 레지스트리 호스트 네임스페이스 대신 사용되는 레지스트리 네임스페이스예요. 이 호스트들은 기본 레지스트리에서 가져오려는 컨테이너 이미지와 아티팩트의 복사본을 담고 있을 수 있기 때문에 미러라고도 불립니다. 각 host/mirror 네임스페이스도 기본 레지스트리 네임스페이스와 거의 같은 방식으로 설정해요. 눈에 띄는 차이는 server를 지정하지 않는다는 점인데, 네임스페이스에 이미 지정되어 있기 때문이에요. 이 레지스트리 호스트 네임스페이스에 대한 호스트 미러 네임스페이스를 설정하는 대략적인 예제 몇 개입니다.

[host."https://mirror.registry"]
  capabilities = ["pull"]
  ca = "/etc/certs/mirror.pem"
  skip_verify = false
  [host."https://mirror.registry".header]
    x-custom-2 = ["value1", "value2"]

[host."https://mirror-bak.registry/us"]
  capabilities = ["pull"]
  skip_verify = true

[host."http://mirror.registry"]
  capabilities = ["pull"]

[host."https://test-1.registry"]
  capabilities = ["pull", "resolve", "push"]
  ca = ["/etc/certs/test-1-ca.pem", "/etc/certs/special.pem"]
  client = [["/etc/certs/client.cert", "/etc/certs/client.key"],["/etc/certs/client.pem", ""]]

[host."https://test-2.registry"]
  client = "/etc/certs/client.pem"

[host."https://test-3.registry"]
  client = ["/etc/certs/client-1.pem", "/etc/certs/client-2.pem"]

[host."https://non-compliant-mirror.registry/v2/upstream"]
  capabilities = ["pull"]
  override_path = true

참고: hosts.toml 파일에서 호스트 미러 네임스페이스 지정에는 재귀(recursion)를 지원하지 않아요. 따라서 다음은 허용되지 않고 지원되지도 않습니다.

[host."http://mirror.registry"]
  capabilities = ["pull"]
  [host."http://double-mirror.registry"]
    capabilities = ["pull"]

더 알아보기 (Learn more)