美文网首页
openshift持久化存储

openshift持久化存储

作者: Nejore | 来源:发表于2019-03-30 17:16 被阅读0次

    存储支持方式:NFS、GlusterFs、cep、samba等
    以下以NFS为例,构建pod的持久化存储
    1.创建NFS共享

    mkdir /var/lib/mynfs
    chown nfsnobody.nfsnobody /var/lib/mynfs
    chmod 700 /var/lib/mynfs
    #如果在/root目录下,需要修改/root目录的权限,否则共享出去的nfs无法挂载
    
    cat /etc/export.d/my.export
    /var/lib/mynfs *(rw,async,all_squash)
    export -a
    exportfs -rv
    systemctl restart nfs
    
    #检查是否可用
    showmount -e nfsServerIp
    mount -t nfs nfsServerIp:/var/lib/mynfs /mnt
    
    #测试可用就行,然后umount
    umount /mnt
    

    2,创建项目等基础资源

    oc new-project lan
    oc new-app --name=myapp --docker-image=URL --insecure-registry 
    
    oc create -f pv.yml
    
    #cat pv.yml
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: mypv
    spec:
      capacity:
        storage: 1Gi 
      accessModes:
        - ReadWriteMany 
      persistentVolumeReclaimPolicy: Retain 
      nfs: 
        path:/var/lib/mynfs
        server: nfsServerIp
        readOnly: false
    

    3,查看myapp的dc配置,获取volume值

    oc get dc
    oc describe dc dcName
    #此处会输出我们需要绑定存储的目录名称,见下图mydc.jpg
    #详情请见官网[https://docs.openshift.com/container-platform/3.5/dev_guide/app_tutorials/maven_tutorial.html](https://docs.openshift.com/container-platform/3.5/dev_guide/app_tutorials/maven_tutorial.html)
    
    

    此处的name即是我们需要绑定存储的volume名称


    mydc.jpg

    4,给pod绑定存储

    bash]  oc volumes dc myDcName --add --overwrite --name=volumeName -t pvc  \
    --claim-name='yourName' 
    --claim-mode='ReadWriteMany/ReadWriteOnce/ReadOnlyMany'  #三种类型可选
    --claim-size=1Gi
    

    5,查看是否生效

    oc describe dc dcName
    

    相关文章

      网友评论

          本文标题:openshift持久化存储

          本文链接:https://www.haomeiwen.com/subject/khlsbqtx.html