Pod的生命周期通常比较短,只要出现了异常,就会创建一个新的Pod来代替它。那容器产生的会随着Pod消亡而自动消失。所以Volume就是为了数据持久化而产生的,和Docker的Volume概念几乎一致,比如它可以为redis容器指定一个hostPath来储存redis数据:
apiVersion: v1kind: Podmetadata:name: redisspec:containers:- name: redisimage: redisvolumeMounts:- name: redis-persistent-storagemountPath: /data/redisvolumes:- name: redis-persistent-storagehostPath:path: /data/
Kubernetes volume支持非常多的插件,可以根据实际需要来选择:
- emptyDir
- hostPath
- gcePersistentDisk
- awsElasticBlockStore
- nfs
- iscsi
- flocker
- glusterfs
- rbd
- cephfs
- gitRepo
- secret
- persistentVolumeClaim
- downwardAPI
- azureFileVolume
- vsphereVolume
