Pod需要设置卷来源(spec.volume)和挂载点(spec.containers.volumeMounts)两个信息后才可以使用相应的Volume
常用的数据卷:
• 本地(hostPath,emptyDir)
• 网络(NFS,Ceph,GlusterFS)
• 公有云(AWS EBS)
• K8S资源(configmap,secret)
一、临时存储卷:emptyDir
创建一个空卷到Pod中,Pod删除,该卷也被删除
默认存储路径为:/var/lib/kubelet/pods/<Pod ID>/volumes/kubernetes.io~empty-dir/
spec:
containers:
- name: empty
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
emptyDir: {}
二、节点存储卷hostPath
挂载节点上的目录或者文件到Pod容器中
挂载宿主机的/tmp目录到Pod容器的/data目录
spec:
containers:
- name: empty
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
hostPath:
path: /tmp
三、网络存储卷NFS
spec:
containers:
- name: empty
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
nfs:
server: 192.168.1.10 #NFS服务器地址
path: /app #NFS共享的目录