數據持久化經常使用的有兩種:node
hostPath 掛載容器宿主機的本地文件夾,直接修改pod的配置web
volumes: - hostPath: path: /data/logging-es type: '' name: elasticsearch-storage
這種方式雖然簡單可是有個致命缺點就是容器必須運行在某個node節點上docker
nodeName: oc-node02
還有就是重點要說的網絡存儲:vim
由於oc是基於k8s的因此k8s支持的存儲類型oc都支持api
k8s支持存儲:https://kubernetes.io/docs/concepts/storage/persistent-volumes/網絡
下面主要說兩個一個是NFS和glusterfsapp
爲docker-registry配置數據持久化elasticsearch
建立pv分佈式
# vim pv.yaml apiVersion: v1 kind: PersistentVolume metadata: name: registry-storage-pv spec: capacity: storage: 100Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain nfs: path: /opt/nfs server: nfs.server readOnly: false # oc create -f pv.yaml
建立pvcspa
# vim pvc.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: registry-storage spec: accessModes: - ReadWriteMany resources: requests: storage: 100Gi # oc project default # oc create -f pvc.yaml
掛載存儲
# oc set volume dc/docker-registry --add --name=registry-storage -t pvc --claim-name=registry-storage --overwrite
# oc set volume dc/docker-registry --add --name=registry-storage -m /registry --overwrite
glusterfs是紅帽自家的分佈式存儲部署起來就很簡單了
修改/etc/ansible/hosts文件加入如下內容
[OSEv3:children] glusterfs [OSEv3:vars] openshift_storage_glusterfs_namespace=app-storage openshift_storage_glusterfs_storageclass=true openshift_storage_glusterfs_storageclass_default=true openshift_storage_glusterfs_block_deploy=true openshift_storage_glusterfs_block_host_vol_size=100 openshift_storage_glusterfs_block_storageclass=true openshift_storage_glusterfs_block_storageclass_default=false [glusterfs] n1.example.com glusterfs_devices='[ "/dev/xvdb", "/dev/xvdc" ]' n1.example.com glusterfs_devices='[ "/dev/xvdb", "/dev/xvdc" ]' n1.example.com glusterfs_devices='[ "/dev/xvdb", "/dev/xvdc" ]'
運行部署程序
# ansible-playbook /root/openshift-ansible/playbooks/openshift-glusterfs/config.yml
部署好以後查看storageclass
# oc get storageclass
其實oc(k8s)是不能支持直接操做glusterfs的是藉助heketi來管理glusterfs卷的,因此heketi的穩定性相當重要
# oc project app-storage
# oc get pod
若是之後在web console 建立pvc都是默認使用glusterfs-storage storageclass動態建立pv和glusterfs卷很方便
能夠看到pv已經自動建好了,固然你刪了pvc pv也會自動刪除,heketi也會刪除關聯的glusterfs卷