containerd managed opt 디렉터리
containerd의 managed opt 디렉터리는 기존 배포 인프라를 그대로 활용해 containerd 의존성을 설치하는 방법을 제공해요. runtime v2와 새로운 shim들이 등장하면서, 여러 shim이나 런타임 의존성을 머신에 내려받는 일이 만만치 않은데요, 이 기능은 그 의존성을 이미지로 만들어 containerd 클라이언트 API로 시스템에 설치할 수 있게 해줘요.
출처: 문서
본문
containerd의 managed /opt 디렉터리를 쓰면 이런 의존성을 제공하는 이미지를 만들고 containerd 클라이언트 API로 시스템에 설치할 수 있어요.
설정:
기본값: /opt/containerd
containerd 설정:
version = 2
[plugins."io.containerd.internal.v1.opt"]
path = "/opt/mypath"
사용법:
코드:
image, err := client.Pull(ctx, "docker.io/crosbymichael/runc:latest")
client.Install(ctx, image)
옵션:
// WithInstallLibs installs libs from the image
func WithInstallLibs(c *InstallConfig) {
}
// WithInstallReplace will replace existing files
func WithInstallReplace(c *InstallConfig) {
}
ctr:
ctr content fetch docker.io/crosbymichael/runc:latest
ctr install docker.io/crosbymichael/runc:latest
버전 관리와 실행 상태 확인은 표준 이미지 명령으로 할 수 있어요.
이미지:
이 이미지들은 반드시 작아야 하고, 필요하다면 바이너리와 라이브러리만 담고 있어야 해요.
FROM scratch
Add runc /bin/runc
containerd는 기본적으로 이미지의 /bin 안에 있는 파일만 추출하고, libs/를 대체하거나 설치하려면 옵션을 추가하면 돼요. 다만 링크 의존성을 줄이려면 이 바이너리들이 정적 빌드일 것을 권장해요.
이 코드는 /opt/containerd 디렉터리를 관리하는 서비스를 추가하고, 인트로스펙션(introspection) 서비스를 통해 그 경로를 호출자에게 제공해요.
테스트 방법:
시스템에서 runc를 지우고 시작해요.
> sudo ctr run --rm docker.io/library/redis:alpine redis
ctr: OCI runtime create failed: unable to retrieve OCI runtime error (open /run/containerd/io.containerd.runtime.v1.linux/default/redis/log.json: no such file or directory): exec: "runc": executable file not found in $PATH: unknown
> sudo ctr content fetch docker.io/crosbymichael/runc:latest
> sudo ctr install docker.io/crosbymichael/runc:latest
> sudo ctr run --rm docker.io/library/redis:alpine redis
1:C 01 Aug 15:59:52.864 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 01 Aug 15:59:52.864 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 01 Aug 15:59:52.864 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 01 Aug 15:59:52.866 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
1:M 01 Aug 15:59:52.866 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
1:M 01 Aug 15:59:52.866 # Current maximum open files is 1024. maxclients has been reduced to 992 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
1:M 01 Aug 15:59:52.870 * Running mode=standalone, port=6379.
1:M 01 Aug 15:59:52.870 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 01 Aug 15:59:52.870 # Server initialized
1:M 01 Aug 15:59:52.870 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 01 Aug 15:59:52.870 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 01 Aug 15:59:52.870 * Ready to accept connections
^C1:signal-handler (1533139193) Received SIGINT scheduling shutdown...
1:M 01 Aug 15:59:53.472 # User requested shutdown...
1:M 01 Aug 15:59:53.472 * Saving the final RDB snapshot before exiting.
1:M 01 Aug 15:59:53.484 * DB saved on disk
1:M 01 Aug 15:59:53.484 # Redis is now ready to exit, bye bye...
Windows인 경우:
FROM mcr.microsoft.com/windows/nanoserver:1809
ADD runhcs.exe /bin/runhcs.exe
> ctr content fetch docker.io/ameyagawde/runhcs:1809 #An example image, not supported by containerd
> ctr install docker.io/ameyagawde/runhcs:1809
/opt/containerd에 대응하는 Windows 경로는 $env:ProgramData\containerd\root\opt예요.
더 알아보기 (Learn more)
- containerd 클라이언트 문서 — Pull/Install 클라이언트 API 이해하기
- containerd 플러그인 문서 — 내부 플러그인 구성 방식
- runtime v2 문서 — shim 아키텍처 개요