Volume
emptyDir, hostPath, PV/PVC
1. emptyDir
1-1) Pod
apiVersion: v1
kind: Pod
metadata:
name: pod-volume-1
spec:
containers:
- name: container1
image: kubetm/init
volumeMounts:
- name: empty-dir
mountPath: /mount1
- name: container2
image: kubetm/init
volumeMounts:
- name: empty-dir
mountPath: /mount2
volumes:
- name : empty-dir
emptyDir: {}
mount | grep mount1
echo "file context" >> file.txt
2. hostPath
2-1) Pod
apiVersion: v1
kind: Pod
metadata:
name: pod-volume-3
spec:
nodeSelector:
kubernetes.io/hostname: k8s-node1
containers:
- name: container
image: kubetm/init
volumeMounts:
- name: host-path
mountPath: /mount1
volumes:
- name : host-path
hostPath:
path: /node-v
type: DirectoryOrCreate
3. PVC / PV
3-1) PersistentVolume
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-03
spec:
capacity:
storage: 2G
accessModes:
- ReadWriteOnce
local:
path: /node-v
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- {key: kubernetes.io/hostname, operator: In, values: [k8s-node1]}
3-2) PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-01
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1G
storageClassName: ""
3-3) Pod
apiVersion: v1
kind: Pod
metadata:
name: pod-volume-3
spec:
containers:
- name: container
image: kubetm/init
volumeMounts:
- name: pvc-pv
mountPath: /mount3
volumes:
- name : pvc-pv
persistentVolumeClaim:
claimName: pvc-01
PV-PVC를 label과 selector를 이용해 연결하는 방법 예시
PersistentVolume
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-04
labels:
pv: pv-04
spec:
capacity:
storage: 2G
accessModes:
- ReadWriteOnce
local:
path: /node-v
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- {key: kubernetes.io/hostname, operator: In, values: [k8s-node1]}
PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-04
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2G
storageClassName: ""
selector:
matchLabels:
pv: pv-04
Tips
hostPath Type
- DirectoryOrCreate : 실제 경로가 없다면 생성
- Directory : 실제 경로가 있어야됨
- FileOrCreate : 실제 경로에 파일이 없다면 생성
- File : 실제 파일이 었어야함