Pod的生命周期通常比较短,只要出现了异常,就会创建一个新的Pod来代替它。那容器产生的会随着Pod消亡而自动消失。所以Volume就是为了数据持久化而产生的,和Docker的Volume概念几乎一致,比如它可以为redis容器指定一个hostPath来储存redis数据:

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: redis
    5. spec:
    6. containers:
    7. - name: redis
    8. image: redis
    9. volumeMounts:
    10. - name: redis-persistent-storage
    11. mountPath: /data/redis
    12. volumes:
    13. - name: redis-persistent-storage
    14. hostPath:
    15. path: /data/

    Kubernetes volume支持非常多的插件,可以根据实际需要来选择:

    • emptyDir
    • hostPath
    • gcePersistentDisk
    • awsElasticBlockStore
    • nfs
    • iscsi
    • flocker
    • glusterfs
    • rbd
    • cephfs
    • gitRepo
    • secret
    • persistentVolumeClaim
    • downwardAPI
    • azureFileVolume
    • vsphereVolume