마운트 시 pod uuid 폴더 생성하기
POD에 NAS 또는 호스트 디스크를 마운트 할 때 POD명으로 폴더를 생성하고 싶다.
기존 mount 방식 :
호스트서버 : /file
POD (1) : /home/app/file
POD (2) : /home/app/file
각 POD가 test.log 파일을 쓰면 /file/test.log 파일 1개로 작성된다.
각 pod별 폴더 경로 추가
호스트서버 : /file
POD (1) : /home/app/file
POD (2) : /home/app/file
POD 1 이 test.log 를 쓸 경우 /file/pod-1/test.log 경로로 파일 생성
POD 2 가 test.log 를 쓸 경우 /file/pod-2/test.log 경로로 파일 생성
된다.
적용 방법
위 POD Deployment 파일
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
apiVersion: apps/v1
kind: Deployment
...
spec:
containers:
- image: {이미지 이름}
env:
- name: POD_NAME # 변수명
valueFrom:
fieldRef:
fieldPath: metadata.name # 실제 배포되는 포드명
volumeMounts:
- name: host-volume
mountPath: /home/app/file # POD 내 /home/app/file 경로 마운트
subPathExpr: $(POD_NAME) # 위 env에서 지정한 POD_NAME으로 폴더가 생성된다.
volumes:
- name: host-volume
hostPath:
path: /file # 호스트 서버의 /file 경로로 마운트 시킨다.
type: DirectoryOrCreate # 경로가 존재하지 않으면 생성한다.
This post is licensed under CC BY 4.0 by the author.