날라가는 것을 방지하자!
컨테이너가 삭제 또는 다시 실행될 때 파일이 사라짐
파드 내의 컨테이너 간의 파일 공유 방법
이를 해결하기 위한 것이 바로 볼륨
컨테이너가 죽으면 파드가 살아있기 때문에 괜찮은데 파드가 죽으면 날라간다.
apiVersion: v1
kind: Pod
metadata:
name: volume-test
labels:
app: volume
spec:
nodeSelector:
kubernetes.io/hostname: node-02
containers:
- name: hello-container1
image: gugucone/hello:9000
volumeMounts:
- name: empty-dir
mountPath: /mount1
ports:
- containerPort: 9000
- name: hello-container2
image: gugucone/hello:8000
volumeMounts:
- name: empty-dir
mountPath: /mount2
ports:
- containerPort: 8000
volumes:
- name : empty-dir
emptyDir: {}
apiVersion: v1
kind: Pod
metadata:
name: volume-test-node-01
labels:
app: volume
spec:
nodeSelector:
kubernetes.io/hostname: node-01
containers:
- name: hello-container1
image: gugucone/hello:8000
volumeMounts:
- name: host-path
mountPath: /db-data
ports:
- containerPort: 8000
volumes:
- name : host-path
hostPath:
path: /data
type: DirectoryOrCreate
yum install nfs-utils
NFS 서비스 설치해주고 chrom 777 /data
권한주고yum install nfs-utils
설치해주고 mount 192.168.181.20:/data /data
가져올 ip와 디렉토리를 마운트해줄 클라이언트 디렉토리를 설정!apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-01
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
local:
path: /node-vol
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node-01
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-01
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1G
storageClassName: ""
apiVersion: v1
kind: Pod
metadata:
name: pod-volume-3
spec:
nodeSelector:
kubernetes.io/hostname: node-01
containers:
- name: container
image: gugucone/hello:8000
ports:
- containerPort: 8000
volumeMounts:
- name: pvc-pv
mountPath: /mount3
volumes:
- name : pvc-pv
persistentVolumeClaim:
claimName: pvc-01