'데이터 엔지니어'로 성장하기

정리하는 걸 좋아하고, 남이 읽으면 더 좋아함

기타/K8S

Kubernetes) Prometheus emptydir disk full_초기화

MightyTedKim 2022. 3. 16. 14:36
728x90
반응형

 

 

개발 서버가 storage가 너무 부족하다 필요없는 파일을 마구 지워도 부족하다.

무엇이 문제일까. 며칠뒤에 다시 와보니 또 부족하다.

$ df -h 
/var/lib/ 100%

보니까 /var/lib/kubelet이 대부분을 먹고 있다.

$ du -h --max-deph=1 /var/lib

자세히 들어가보니, 하나의 폴더가 192G다. 대충 empty-dir 안잡고 pod 돌린 거라고 추정

$ du -h --max-deph=1 /var/lib/kubelet/pods/
/var/lib/kubelet/pods/e2164860-fe59-4520-a79e-de7ca32f302f/volumes/kubernetes.io~empty-dir/prometheus-storage-volume:

더 들어가본다. prometheus인듯 하다. etc-hosts가 있다. 출력해본다.

$  ll
drwxr-x--- 3 root root  24 12월 27 12:42 containers
-rw-r--r-- 1 root root 236 12월 27 12:42 etc-hosts
drwxr-x--- 3 root root  37 12월 27 12:42 plugins
drwxr-x--- 5 root root  96 12월 27 12:42 volumes

$ cat etc-hosts
# Kubernetes-managed hosts file.
10.233.98.193   prometheus-deployment-596c9978d9-8gd6c

찾았다. prometheus-deployment라는 녀석이 문제였다. 검색해서 ns까지 찾았다.

$ k get all -A | grep prometheus-deployment-596c9978d9-8gd6c
monitoring                     pod/prometheus-deployment-596c9978d9-8gd6c             1/1     Running     0          79d

deployment를 보니, hello-world로 띄울 때 pvc를 만들어주지 않아서 문제였다.

$ cat pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: prom-storage
  namespace: monitoring
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  storageClassName: rook-ceph-block

pvc를 만들어주고, deployment에 설정을 해준다.

$ cat prometheus-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-deployment
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus-server
  template:
    metadata:
      labels:
        app: prometheus-server
    spec:
      containers:
        - name: prometheus
          image: tedkim/prometheus:v20211027
          imagePullPolicy: IfNotPresent
          args:
            - "--config.file=/etc/prometheus/prometheus.yml"
            - "--storage.tsdb.path=/prometheus/"
          resources:
            limits:
              memory: "4Gi"
              cpu: "2000m"
            requests:
              memory: "2Gi"
              cpu: "100m"
          ports:
            - containerPort: 9090
          volumeMounts:
            - name: conf
              mountPath: /etc/prometheus/
            - name: storage
              mountPath: /prometheus/
      volumes:
        - name : conf
          configMap:
            defaultMode: 420
            name: prometheus-server-conf
        - name : storage
          persistentVolumeClaim:
            claimName: prom-storage

replicaset이 수정되고, pod가 재실행된다.

$ df -h -all
18%

99%에서 18%로 disk 사용량이 줄었다.

disk 100%면 kubectl도 못하는데, 큰일날 뻔했다.

 

728x90
반응형