이쿠의 슬기로운 개발생활

함께 성장하기 위한 보안 개발자 EverNote 내용 공유

클라우드/Kubernetes

104. 실행 중인 container에 mount하는 방법

이쿠우우 2022. 7. 5. 08:28
반응형

 

 
 
 
 

실행 중인 container에 mount하는 방법

 

 

목표

 
kubernetes cluster에서 container mount 는
pod 생성 시에 volume 설정을 통해 mount하는 방법이 있음.
하지만 이미 running 상태로 동작 중인 pod의 container에 mount해야하는 경우도 있음.
이에 따라 실행 중인 container에 mount하는 방법을 알아봄.
 
 

 

test 환경

 
kubernetes cluster 중 
control node에서 test를 진행함
kubernetes cluster에서 container runtime으로 containerd를 사용하고 있음.
cluster 정보는 다음과 같음

 
[Containerd : 1.4.12]

 
 

 

kubernetes cluster에 배포되어있는 container 확인

 
해당 test환경에서는 조회된 pod/iksoon-deployment-7848564b67-cb6cb 를 대상으로 진행해봄
 

pod 확인

 
[명령어]
kubectl get all -o wide

 

pod의 container 확인

 
[명령어]
kubectl describe pod/dnsutils | grep "Container ID"

 
위의 정보로 container는
kube.worker.node host에 배포되어있고
container ID는 5e540cf73e8482e7305a7075441ad81f31d17095db9e17ecdcfa35f88389e382
임을 알 수 있음.
 
 
 

container의 실제 directory 경로로 이동

container가 배포되어있는
kube.worker.node host에서 진행.
 
[명령어]
mount | grep overlay | awk '{print $3}' | grep "확인하고자 하는 container id"
ex) mount | grep overlay | awk '{print $3}' | grep 5e540cf73e8482e7305a7075441ad81f31d17095db9e17ecdcfa35f88389e382

 
 
[명령어]
cd "위에서 확인한 경로"
ex) cd /run/containerd/io.containerd.runtime.v2.task/k8s.io/5e540cf73e8482e7305a7075441ad81f31d17095db9e17ecdcfa35f88389e382/rootfs

 
kubectl exec -it 명령으로 접속한 container의 directory 정보와 일치함을 알 수 있음.
 
 
 
 

container에 mount

 
mount directory 정보는 다음과 같음
해당 directory를 container에 mount 함.

 

mount할 directory 생성

 
container directory에 mount할 directory를 생성.
 
[명령어]
mkdir ./temp1
 
 

mount 진행

 
[명령어]
mount --bind /root/mountTest/ ./temp1/
 
test에서는 기존 directory를 mount 하기 때문에 --bind 옵션을 사용함.
--bind 옵션 : 특정 디렉토리를 다른 디렉토리에 붙일 수 있음

 
정상적으로 /root/mountTest directory가 container의 temp1 directory에 mount 된 것을 확인할 수 있음.
 
 

kubectl exec 명령으로 비교

[명령어]
kubectl exec -it pod/iksoon-deployment-7848564b67-cb6cb -- bash
 
실행되고 있던 container에 정상적으로 mount 된 것을 확인할 수 있음.

반응형