티스토리 뷰
Volume (local)
Pod 안의 컨테이너 간 디렉토리를 공유하는 방법과 컨테이너의 특정 디렉토리를 호스트 디렉토리와 연결하는 방법을 알아봅니다.
subicura.com
Docker의 volume 처럼 kubernetes 도 volume 이 있다.
만약 볼륨이 없다면 db 컨테이너가 사라졌을때 데이터도 같이 사라질 것이다.
empty-dir
Pod 안에 속한 컨테이너 간 디렉토리를 공유하는 방법
empty-dir.yml
apiVersion: v1
kind: Pod
metadata:
name: sidecar
spec:
containers:
- name: app # 로그 기록 app
image: busybox
args: # 1초마다 example.log 에 로그 기록
- /bin/sh
- -c
- >
while true;
do
echo "$(date)\n" >> /var/log/example.log;
sleep 1;
done
volumeMounts: # 볼륨 마운트
- name: varlog
mountPath: /var/log
- name: sidecar # 로그 읽는 sidecar
image: busybox
args: [/bin/sh, -c, "tail -f /var/log/example.log"]
volumeMounts: # 볼륨 마운트
- name: varlog
mountPath: /var/log
volumes: # 볼륨 (하나의 pod 내에 가상의 디렉토리 생성해서 공유)
- name: varlog
emptyDir: {}
- app 컨테이너: 1초마다 로그 기록
- sidecar 컨테이너: 로그 읽음
- 두 컨테이너 모두 varlog 볼륨에 마운트
로그 확인
kubectl logs -f sidecar -c sidecar
- -f: follow, 로그 계속해서 스트리밍
- sidecar: pod 이름
- -c sidecar: 컨테이너 이름
- sidecar 컨테이너에서 로그를 볼 수 있다
- app과 sidecar 컨테이너가 varlog 볼륨을 공유하기 때문
hostpath
호스트 디렉토리를 컨테이너 디렉토리에 연결한다.
hostpath.yml
apiVersion: v1
kind: Pod
metadata:
name: host-log
spec:
containers:
- name: log # sleep 으로 컨테이너가 죽지 않도록 유지만 함
image: busybox
args: ["/bin/sh", "-c", "sleep infinity"]
volumeMounts:
- name: varlog
mountPath: /host/var/log
volumes:
- name: varlog
hostPath: # host의 볼륨
path: /var/log
이렇게 내가 yml에서 지정한대로 컨테이너의 '/host/var/log' 와 호스트의 '/var/log' 가 공유된다.
'Web > Kubernetes' 카테고리의 다른 글
Kubernetes Secret (0) | 2024.01.08 |
---|---|
Kubernetes ConfigMap (0) | 2024.01.08 |
Kubernetes Ingress (0) | 2024.01.08 |
minikube addons enable ingress 시 MK_ADDON_ENABLE 에러 (0) | 2024.01.08 |
Kubernetes로 배포하기, yml 정리 (0) | 2024.01.06 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- two pointer
- MVC
- back tracking
- DP
- Unity
- dfs
- CSS
- 자료구조
- priority queue
- Tree
- Dijkstra
- permutation
- C++
- Spring
- floyd warshall
- recursion
- Python
- Kruskal
- BFS
- db
- 이분탐색
- 재귀
- greedy
- Stack
- graph
- 조합
- Brute Force
- Implementation
- binary search
- C
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함