docker to crio 사용시 알아야 할 것들

Jerry(이정훈)
11 min readApr 21, 2021

docker -> crio(혹은 containerd) 변경 시 알아야 할 것들 정리해 보았습니다. 결론을 먼저 말씀드리면, 별로 알아야 할게 없습니다. ^^ docker image build 등을 할 때는 필요하겠지만, 이미 kube가 실행되는 node에서 docker 관련 명령어를 사용할 일이 없었습니다. 기존에도 별로 사용하지 않으니 변경된다고 달라질 게 없겠죠. 개발자는 당연하고 운영자들도 docker 지원하지 않는다고 쫄 필요 없을 것 같습니다. (조만간 docker도 container runtime 지원해서 다시 kube 지원하지 않을까 싶습니다.)

몇가지만 확인보겠습니다. (설치는 kubespray 사용 시 옵션만 변경하면 되니 생략 하겠습니다.)

Container Runtime, crio 지정

1. crio 서비스 재 시작 시 POD 영향 없음

기존 docker 환경에서는 docker service가 재시작되면 해당 노드의 pod 전체가 재시작되지만 crio(혹은 containerd)는 아닙니다. 아래 예시를 보시면,

‘crio’ service 재시작 하여도 pod 영향 없음(containerd 마찬가지)

반면 docker service 재시작하면 해당 node의 전체 pod 재기동

  • 주르륵 Terminating 되고 있습니다.

2. 다음으로 새롭게 사용하는 crictl 명령어 알아 보겠습니다. docker 대신 crictl 명령어 사용합니다. (cri, Container Runtime Interface)

해당 노드에서 crictl help를 치시면… (root로 실행하셔야 합니다.)

[root@node1 ~]# crictl --help
NAME:
crictl - client for CRI
USAGE:
crictl [global options] command [command options] [arguments...]
VERSION:
v1.20.0
COMMANDS:
attach Attach to a running container
create Create a new container
exec Run a command in a running container
version Display runtime version information
images, image, img List images
inspect Display the status of one or more containers
inspecti Return the status of one or more images
imagefsinfo Return image filesystem info
inspectp Display the status of one or more pods
logs Fetch the logs of a container
port-forward Forward local port to a pod
ps List containers
pull Pull an image from a registry
run Run a new container inside a sandbox
runp Run a new pod
rm Remove one or more containers
rmi Remove one or more images
rmp Remove one or more pods
pods List pods
start Start one or more created containers
info Display information of the container runtime
stop Stop one or more running containers
stopp Stop one or more running pods
update Update one or more running containers
config Get and set crictl client configuration options
stats List container(s) resource usage statistics
completion Output shell completion code
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--config value, -c value Location of the client config file. If not specified and the default does not exist, the program's directory is searched as well (default: "/etc/crictl.yaml") [$CRI_CONFIG_FILE]
--debug, -D Enable debug mode (default: false)
--image-endpoint value, -i value Endpoint of CRI image manager service (default: uses 'runtime-endpoint' setting) [$IMAGE_SERVICE_ENDPOINT]
--runtime-endpoint value, -r value Endpoint of CRI container runtime service (default: uses in order the first successful one of [unix:///var/run/dockershim.sock unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock]). Default is now deprecated and the endpoint should be set instead. [$CONTAINER_RUNTIME_ENDPOINT]
--timeout value, -t value Timeout of connecting to the server in seconds (e.g. 2s, 20s.). 0 or less is set to default (default: 2s)
--help, -h show help (default: false)
--version, -v print the version (default: false)

이 중 굵은 글씨 정도면 될 것 같습니다. 기존 docker 환경에서도 실행되는 컨테이너 리스트, 이미지 정보, 가끔 로그 확인 정도 필요하니 동일합니다. kubectl을 사용하고 문제가 있을 때 가끔 debugging 용도로만 사용 합니다.

공식 홈페이지에도 debugging 용도로 사용한다고 나와 있습니다.

가장 큰 차이는 기존 docker와 다르게 현재 실행되는 POD를 바로 확인 할 수 있습니다. (docker도 한번더 거쳐서 알 수 있지만)

[root@node1 ~]# crictl pods
POD ID CREATED STATE NAME NAMESPACE ATTEMPT RUNTIME
c375f44f40681 42 hours ago Ready openebs-ndm-operator-67876b4dc4-847rg openebs 1 (default)
72679e4bb7ad6 42 hours ago Ready metrics-server-bc4467d77-jktwl kube-system 1 (default)
fb562d24f0d30 42 hours ago Ready coredns-657959df74-7m87w kube-system 2 (default)
9e3219a9e2a33 42 hours ago Ready
(...)

물론 컨테이너 리스트도 확인 가능합니다.

[root@node1 ~]# crictl ps
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID
d88f79aefb8d0 89fa97d9bd32d 42 hours ago Running openebs-provisioner-hostpath 4 9e3219a9e2a33
b8b3f8c7a119e 9759a41ccdf0f 42 hours ago Running metrics-server 2 72679e4bb7ad6
8bbfae38b5dfc a6b505c0e9f60 42 hours ago Running chaos-operator 1 1b51dd39648eb
3dded36785df4 aedf47d433f18 42 hours ago Running nginx 1 664a0e8a6b6c8
3b809afd6f5b2 aedf47d433f18 42 hours ago Running nginx 1 4c85c560d7681

debugging 용도로 컨테이너 접속이 필요하면 동일하게 exec -it 명령어를 사용합니다. (kubectl 사용이 대다수 이겠지만) 이 때 POD ID를 사용하는 게 아니고 CONTAINER ID를 사용 합니다. POD 이름을 보고 container id 한번 더 찾아가야 되니 번거롭습니다.

[spkr@erdia22 bumin (scluster:redis)]$ crictl exec --help
NAME:
crictl exec - Run a command in a running container
USAGE:
crictl exec [command options] CONTAINER-ID COMMAND [ARG...]
[root@node1 ~]# crictl exec -it 3dded36785df4 sh
/ # ps
PID USER TIME COMMAND
1 root 0:00 nginx: master process nginx -g daemon off;
6 nginx 0:46 nginx: worker process
7 root 0:00 sh
12 root 0:00 ps

로그 확인하는 것도 동일하게 CONTAINER-ID로 보셔야 합니다.

[root@node1 ~]# crictl logs -f 3b809afd6f5b2
10.233.92.0 - - [19/Apr/2021:23:46:43 +0000] "GET / HTTP/1.1" 200 7248 "-" "Go-http-client/1.1" "-"
10.233.92.0 - - [19/Apr/2021:23:46:43 +0000] "GET / HTTP/1.1" 200 7248 "-" "Go-http-client/1.1" "-"
10.233.92.0 - - [19/Apr/2021:23:46:43 +0000] "GET / HTTP/1.1" 200 7248 "-" "Go-http-client/1.1" "-"

3. insecure_registries 등록

docker 와 동일하게 Local Private Registry를 사용하시면 insecure_registries 정보를 /etc/crio/crio.conf 등록합니다.

[admin@node1 ~]$ sudo vi /etc/crio/crio.conf

추가로 registry 로그인 정보 역시 기존 docker 환경과 동일하게 kube secret로 등록합니다.

[spkr@erdia22 ~ (dzbumin:nginx)]$ k get secret
NAME TYPE DATA AGE
default-token-zh547 kubernetes.io/service-account-token 3 21h
regcred kubernetes.io/dockerconfigjson 1 16h

이상 몇가지만으로 충분한, crio 사용시 알아야 할 것들입니다.

Diamanti 및 Managed Kubernetes Service 문의 : leejunghoon@spkr.co.kr

--

--

Jerry(이정훈)

DevOps/Automation Engineer 60살까지 콘솔 잡는 엔지니어를 목표로 느리게 생각하고 있습니다.