mingming

ephemeral-storage 본문

kubernetes

ephemeral-storage

mingming_96 2023. 9. 21. 23:28

1. 상황 발생

 

집에 도착해 VM을 켜보니 어제까지 잘 작동했던 pod가 계속 죽는 현상이 발생해 굉장히 당황스러웠는데 해당 로그를 살펴본 결과 노드의 자원 부족이 원인이었습니다. 

 

root@master:~# kubectl get pods
NAME                                                 READY   STATUS    RESTARTS      AGE
jenkins-0                                            0/2     Pending   0             2m38s
prometheus-alertmanager-0                            1/1     Running   0             19m
prometheus-kube-state-metrics-5b74ccb6b4-bpt4w       1/1     Running   2 (14m ago)   52m
prometheus-prometheus-node-exporter-2jd2g            1/1     Running   2 (14m ago)   36m
prometheus-prometheus-node-exporter-wmfn7            1/1     Running   7 (14m ago)   3d1h
prometheus-prometheus-pushgateway-79ff799669-stnk5   1/1     Running   2 (14m ago)   52m
prometheus-server-58f4d79c6-79w7t                    2/2     Running   0             11m
prometheus-server-58f4d79c6-gq2gh                    0/2     Unknown   2             25m

 

2. 문제 상황 인지 

Events:
  Type     Reason            Age    From               Message
  ----     ------            ----   ----               -------
  Warning  FailedScheduling  2m37s  default-scheduler  0/2 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }, 1 node(s) had untolerated taint {node.kubernetes.io/disk-pressure: }. preemption: 0/2 nodes are available: 2 Preemption is not helpful for scheduling..

스케쥴링에 실패했다는 경고메세지를 확인했습니다. 

 

Status:           Failed
Reason:           Evicted
Message:          The node was low on resource: ephemeral-storage. Threshold quantity: 1806145607, available: 1728800Ki.

해당 이슈를 해결하기위해 로그를 이것저것 뒤저보던 중 위와 같은 경고를 확인할 수 있었습니다.  ephmeral-storage가 부족하다고 하네요 

 

ephemeral-storage ( 임시 볼륨 )

 

ephemeral-storage는 kubernetes 클러스터 내에서 사용되는 임시 스토리지를 나타냅니다. 즉 노드의 스토리지 공간이라고 이해하셔도 될거 같습니다. 

임시 볼륨에는 다양한 종류가 있지만 가장 대표적으로 사용되는 emptyDir , configMap , secret 등이 있습니다. 

따라서 pod 혹은 리소스가 실행중에 생성되는 로그 , 임시파일 , 캐시파일 , 메타데이터 등이 ephemeral-storage에 저장되고 데이터가 쌓이다보니 스토리지 부족 현상이 발생한 것 같습니다. 

제 경우 실습 목적으로 matser node 1대와 worker node 1대를 사용했기 때문에 그런것 같네요

 

3. 문제 해결

 

먼저, 해당 node로 원격접속해 볼륨의 사용량을 체크해봤습니다.  

root@worker1:~# df -h
Filesystem                               Size  Used Avail Use% Mounted on
udev                                     1.4G     0  1.4G   0% /dev
tmpfs                                    291M  2.3M  289M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv         12G  8.7G  2.1G  82% /
tmpfs                                    1.5G     0  1.5G   0% /dev/shm
tmpfs                                    5.0M     0  5.0M   0% /run/lock
tmpfs                                    1.5G     0  1.5G   0% /sys/fs/cgroup
/dev/loop0                                41M   41M     0 100% /snap/snapd/20092
/dev/loop1                                92M   92M     0 100% /snap/lxd/24061
/dev/loop2                                64M   64M     0 100% /snap/core20/2015
/dev/loop3                                64M   64M     0 100% /snap/core20/1974
/dev/loop4                                41M   41M     0 100% /snap/snapd/19993
/dev/sda2                                2.0G  234M  1.6G  13% /boot

역시나 사용량이 꽤 높았습니다. 해결 방법엔 여려가지가 있겠지만 우선 저의 경우 마운트된 논리볼륨의 사이즈를 늘려주었습니다.

해당 이슈를 찾아보니 ephemeral-storage 리소스 사용량을 Limit하는 방식의 해결책을 많이 제시했지만 기본적으로 볼륨의 사이즈가 많이 부족해 볼륨 사이즈를 늘려주는 방식을 채택했습니다. 

 

우선 Volumegroup에 할당할 수 있는 자원이 남아 있는지 확인했습니다. 

root@worker1:~# vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <23.00 GiB
  PE Size               4.00 MiB
  Total PE              5887
  Alloc PE / Size       2943 / <11.50 GiB
  Free  PE / Size       2944 / 11.50 GiB
  VG UUID               2CHLFh-w930-kL8Y-HCPD-nIe4-KaAI-8cG5Yj

확인해보니 할당할 수 있는 자원은 충분하네요 그럼 바로 논리볼륨 사이즈를 늘려보도록 하겠습니다.

 

root@worker1:~# lvextend -L17G /dev/ubuntu-vg/ubuntu-lv 
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <11.50 GiB (2943 extents) to 17.00 GiB (4352 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

성공적으로 사이즈가 증설된걸 확인할 수 있습니다. 

 

root@master:~# kubectl get pods
NAME                                                 READY   STATUS    RESTARTS      AGE
jenkins-0                                            2/2     Running   0             11m
prometheus-alertmanager-0                            1/1     Running   0             43m
prometheus-kube-state-metrics-5b74ccb6b4-bpt4w       1/1     Running   2 (38m ago)   77m
prometheus-prometheus-node-exporter-2jd2g            1/1     Running   2 (38m ago)   61m
prometheus-prometheus-node-exporter-wmfn7            1/1     Running   7 (38m ago)   3d2h
prometheus-prometheus-pushgateway-79ff799669-stnk5   1/1     Running   2 (38m ago)   77m
prometheus-server-58f4d79c6-79w7t                    2/2     Running   0             36m

조금 후 다시 확인해보니 pod가 모드 정상 작동중인 것을 확인할 수 있었습니다. 

 

4. pod 리소스 할당하기

pod 의 리소스를 제한하는 방법에 대해 알아보겠습니다. 전에도 해당 사항에 대해 다룬 적이 있으니 확인해보시면 좋을 것 같습니다. 

        resources:
          requests:
            ephemeral-storage: "1024Mi"
          limits:
            ephemeral-storage: "2048Mi"

위와 같이 pod의 spec을 지정해주면 ephemeral-storage의 사용량을 제한할 수 있습니다. Limit을 설정하지 않으면 데이터가 무한정으로 늘어날 수 있어 다른 pod들이 정상작동하지 않을 수 있습니다. 단순한 실습용도로 만든 VM이여서 다행이란 생각이 드네요