数据持久化经常使用的有两种: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卷