안녕하세요?
AWS EKS를 사용하다 보면, 간혹 워커 노드에 접속해서 디버깅을 할 때가 있습니다.
EKS는 1.24 버전 부터는 Dockershim을 더이상 지원하지 않고 Containerd만을 지원하도록 되었습니다.
(https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/dockershim-deprecation.html)
그런데, 저는 Docker만 주로 사용했고, Containerd의 ctr cli는 잘 몰라서 많은 부분을 고생했는데요.
(이러한 부분을 고려해서, nerdctl이라는 것도 있는데요. 이부분은 추가로 다루도록 하겠습니다.)
관련해서, ctr cli에서 AWS ECR(Elastic Container Registry)에 로그인해서 이미지를 다운받을 수 있는 방법을 알아보도록 하겠습니다.
EKS 워커 노드 ssh 접속
우선, EKS의 워커 노드에 ssh 접속해야 합니다. EKS의 워커 노드에 접속하는 방법은 여러가지 방법이 있는데요.
저는 node-shell을 사용해서 접근하도록 하겠습니다. 편의상 여기서는 'node1' 이라는 노드에 접근하는 것으로 진행하도록 하겠습니다.
(https://github.com/kvaps/kubectl-node-shell)
$ kubectl node-shell node1
spawning "nsenter-0g6f75" on "node1"
If you don't see a command prompt, try pressing enter.
[root@node1 /]#
아래 ctr 사용 방법을 보면, Docker와는 명령어가 완전히 다른 것을 볼 수 있습니다.
(하지만.. 얼추 비슷하기는 합니다..)
[root@node1 /]# ctr --help
NAME:
ctr -
__
_____/ /______
/ ___/ __/ ___/
/ /__/ /_/ /
\___/\__/_/
containerd CLI
USAGE:
ctr [global options] command [command options] [arguments...]
VERSION:
1.6.19
DESCRIPTION:
ctr is an unsupported debug and administrative client for interacting
with the containerd daemon. Because it is unsupported, the commands,
options, and operations are not guaranteed to be backward compatible or
stable from release to release of the containerd project.
COMMANDS:
plugins, plugin provides information about containerd plugins
version print the client and server versions
containers, c, container manage containers
content manage content
events, event display containerd events
images, image, i manage images
leases manage leases
namespaces, namespace, ns manage namespaces
pprof provide golang pprof outputs for containerd
run run a container
snapshots, snapshot manage snapshots
tasks, t, task manage tasks
install install a new package
oci OCI tools
shim interact with a shim directly
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--debug enable debug output in logs
--address value, -a value address for containerd's GRPC server (default: "/run/containerd/containerd.sock") [$CONTAINERD_ADDRESS]
--timeout value total timeout for ctr commands (default: 0s)
--connect-timeout value timeout for connecting to containerd (default: 0s)
--namespace value, -n value namespace to use with commands (default: "default") [$CONTAINERD_NAMESPACE]
--help, -h show help
--version, -v print the version
Containerd가 Docker와 가장 다른 점으로 꼽자면, 저는 namespace를 선택할 것 같습니다. docker의 경우에는 별도로 namespace 지정을 하지 않고 모든 자원들이 보이지만, containerd의 경우에는 namespace 개념이 추가되면서 namespace를 지정하지 않으면 자원들이 보이지 않습니다.
예를 들어, EKS에서 사용되는 자원들은 기본 네임스페이스가 아니라 'k8s.io' 라는 namespace에 저장되어 있기 때문에, 항상 -n k8s.io 를 추가해줘야만 합니다.
[root@node1 /]# ctr ns ls
NAME LABELS
k8s.io
[root@node1 /]# ctr i ls
REF TYPE DIGEST SIZE PLATFORMS LABELS
[root@node1 /]# ctr -n k8s.io images ls
REF TYPE DIGEST SIZE PLATFORMS LABELS
066635153087.dkr.ecr.il-central-1.amazonaws.com/amazon-k8s-cni-init:v1.12.5-eksbuild.2 application/vnd.docker.distribution.manifest.list.v2+json sha256:11f4cdab54f34da71ecb209ab0d345e58c861ca143832582f69946a26af3eaea 20.8 MiB linux/amd64,linux/arm64 io.cri-containerd.image=managed
......
ctr을 사용해서 ECR 로그인
여기서, 이제 ECR로부터 image를 pull 하기 위해서는 ECR에 로그인을 해줘야만 합니다.
아래 처럼, 로그인에 필요한 정보를 export 하면 이제 ECR로부터 이미지 가져오기 위한 준비는 전부 끝났습니다.
[root@node1 /]# export ECR_REGION=ap-northeast-2
[root@node1 /]# export ECR_PASSWORD=$(aws ecr get-login-password --region $ECR_REGION)
이후 부터는, Docker에서 하던 것처럼 image를 pull 하면 아래처럼 다운로드가 시작 됩니다.
[root@node1 /]# ctr i pull -u "AWS:$ECR_PASSWORD" <ecr-image-url>
<ecr-image-url>: resolved |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:0d3857b14dadf23aecd69498bd6e5a3d9ef7f424923baac0f73a6c3b8d3b750a: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:025b8e01ae4769cc49aba6764273eef357bbe654a6295e9e1f7014b1e28e9f52: downloading |------------------------------------
지금까지 AWS EKS 워커 노드에서 AWS ECR에 로그인하는 방법을 소개해 드렸는데요.
만약, AWS EKS 워커노드에서 container 이미지를 pull 하는데 오랜 시간이 걸린다면, 미리 AWS EC2 Image Builder를 통해서 AWS EKS 워커 노드 AMI에 미리 pull 해놓고 사용하는 방법을 고려할 수도 있습니다.
'개발 > AWS EKS' 카테고리의 다른 글
[EKS] Gatekeeper (1) | 2024.04.15 |
---|---|
[K8S] Ephemeral Container (0) | 2024.03.07 |
[EKS] Knative volume support - PVC (0) | 2024.03.06 |
DockerHub 이미지를 Private Registry에 업로드 (0) | 2024.02.19 |
[Kubernetes] initContainer 와 containers의 volume 공유 (2) | 2024.02.07 |