006.OpenShiefc局部性存储点
一 持久存储
1.1 持久存储概述
1.2 持久存储场景
1.3 持久存储相关概念
1.4 持久存储插件
- NFS
- GlusterFS
- OpenStack Cinder
- Ceph RBD
- AWS Elastic Block Store (EBS)
- GCE Persistent Disk
- iSCSI
- Fibre Channel
- Azure Disk and Azure File
- FlexVolume (allows for the extension of storage back-ends that do not have a built-in plug-in)
- VMWare vSphere
- Dynamic Provisioning and Creating Storage Classes
- Volume Security
- Selector-Label Volume Binding
1.5 PV访问模式
访问模式 | CLI缩写 | 描述 |
ReadWriteOnce | RWO | 卷可以被单个节点挂载为读/写 |
ReadOnlyMany | ROX | 卷可以由许多节点以只读方式挂载 |
ReadWriteMany | RWX | 卷可以被许多节点挂载为读/写 |
1.6 Persistent Volume Storage Classes
1.7 创建pv和PVC资源
- 创建持久卷
- 定义持久卷声明
- 使用持久存储
1.8 使用NFS的PV
- 属于nfsnobody用户和组。
- 拥有rwx------权限(即0700)。
- 使用all_squash选项
1# setsebool -P virt_use_nfs=true2# setsebool -P virt_sandbox_use_nfs=true
1.9 NFS回收政策
1.10 Supplemental group
1 [root@node ~]# showmount -e2 Export list for master.lab.example.com:
3 /var/export/nfs-demo *
4 [root@services ~]# cat /etc/exports.d/nfs-demo.conf
5 /var/export/nfs-demo
6 ...
7 [root@services ~]# ls -lZ /var/export -d
8 drwx------. 10000000 650000 unconfined_u:object_r:usr_t:s0 /var/export/nfs-demo
1.11 通过fsgroup使用块存储
1.12 SELINUX和卷security
1.13 ELinuxContext选项
- MustRunAs
- RunAsAny
二 持久卷练习
2.1 前置准备
2.2 本练习准备
1 [student@workstation ~]$ lab deploy-volume setup
2.3 配置NFS
1 [root@services ~]# less -FiX /root/DO280/labs/deploy-volume/config-nfs.sh2 [root@services ~]# /root/DO280/labs/deploy-volume/config-nfs.sh #创建NFS
3 Export directory /var/export/dbvol created.
4 [root@services ~]# showmount -e #确认验证
2.4 node节点挂载NFS
1 [root@node1 ~]# mount -t nfs services.lab.example.com:/var/export/dbvol /mnt2 [root@node1 ~]# mount | grep /mnt
3 [root@node1 ~]# ll -a /mnt/ #检查相关权限
1 [root@node1 ~]# umount /mnt/ #卸载
2.5 创建持久卷
1 [student@workstation ~]$ oc login -u admin -p redhat https://master.lab.example.com2 [student@workstation ~]$ less -FiX /home/student/DO280/labs/deploy-volume/mysqldb-volume.yml
3 apiVersion: v1
4 kind: PersistentVolume
5 metadata:
6name: mysqldb-volume
7 spec:
8 capacity:
9 storage: 3Gi
10 accessModes:
11 - ReadWriteMany
12 nfs:
13path: /var/export/dbvol
14 server: services.lab.example.com
15 persistentVolumeReclaimPolicy: Recycle
16 [student@workstation ~]$ oc create -f /home/student/DO280/labs/deploy-volume/mysqldb-volume.yml
17 [student@workstation ~]$ oc get pv #查看PV
18 NAME CAPACITYACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
19 mysqldb-volume 3Gi RWX Recycle Available 1m
2.6 创建项目
1 [student@workstation ~]$ oc login -u developer -p redhat https://master.lab.example.com2 [student@workstation ~]$ oc new-project persistent-storage
2.7 部署应用
1 [student@workstation ~]$ oc new-app --name=mysqldb \2 --docker-image=registry.lab.example.com/rhscl/mysql-57-rhel7 \
3 -e MYSQL_USER=ose \
4 -e MYSQL_PASSWORD=openshift \
5 -e MYSQL_DATABASE=quotes
6 [student@workstation ~]$ oc status #确认验证
7 In project persistent-storage on server https://master.lab.example.com:443
8
9
10 svc/mysqldb - 172.30.39.72:3306
11 dc/mysqldb deploys istag/mysqldb:latest
12 deployment #1 deployed 58 seconds ago - 1 pod
2.8 配置持久卷
1 [student@workstation ~]$ oc describe pod mysqldb | grep -A2 'Volumes' #查看当前pod的Volume2 Volumes:
3 mysqldb-volume-1:
4 Type: EmptyDir (a temporary directory that shares a pod's lifetime)
5 [student@workstation ~]$ oc set volumes dc mysqldb \
6 --add --overwrite --name=mysqldb-volume-1 -t pvc \
7 --claim-name=mysqldb-pvclaim \
8 --claim-size=3Gi \
9 --claim-mode='ReadWriteMany' #修改dc并创建PVC
10 [student@workstation ~]$ oc describe pod mysqldb | grep -E -A 2 'Volumes|ClaimName' #查看验证
1 [student@workstation ~]$ oc get pvc #查看PVC2 NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
3 mysqldb-pvclaim Bound mysqldb-volume 3Gi RWX 2m
2.9 端口转发
1 [student@workstation ~]$ oc get pod2 NAME READY STATUS RESTARTS AGE
3 mysqldb-2-r7wz8 1/1 Running 0 4m
4 [student@workstation ~]$ oc port-forward mysqldb-2-r7wz8 3306:3306
2.10 测试数据库
1 [student@workstation ~]$ mysql -h127.0.0.1 -uose -popenshift \2 quotes < /home/student/DO280/labs/deploy-volume/quote.sql #填充数据测试
3 [student@workstation ~]$ mysql -h127.0.0.1 -uose -popenshift \
4 quotes -e "select count(*) from quote;" #确认填充完成
5 [student@workstation ~]$ ssh root@services ls -la /var/export/dbvol #查看NFS服务端数据
6 ……
7 drwxr-x---. 2 nfsnobody nfsnobody 54 Jul 21 23:43 quotes
8 ……
9 [student@workstation ~]$ ssh root@services ls -la /var/export/dbvol/quotes
10 total 116
11 drwxr-x---. 2 nfsnobody nfsnobody 54 Jul 21 23:43 .
12 drwx------. 6 nfsnobody nfsnobody 4096 Jul 21 23:39 ..
13 -rw-r-----. 1 nfsnobody nfsnobody 65 Jul 21 23:39 db.opt
14 -rw-r-----. 1 nfsnobody nfsnobody 8584 Jul 21 23:43 quote.frm
15 -rw-r-----. 1 nfsnobody nfsnobody 98304 Jul 21 23:44 quote.ibd
2.11 删除PV
1 [student@workstation ~]$ oc delete project persistent-storage #删除项目2 project "persistent-storage" deleted
3 [student@workstation ~]$ oc delete pv mysqldb-volume #删除PV
4 persistentvolume "mysqldb-volume" deleted
2.12 验证持久性
1 [student@workstation ~]$ ssh root@services ls -la /var/export/dbvol2 ……
3 drwxr-x---. 2 nfsnobody nfsnobody 54 Jul 21 23:43 quotes
4 ……
5 [student@workstation ~]$ ssh root@services rm -rf /var/export/dbvol/* #使用rm才可以彻底删除
三 私有仓库持久存储
3.1 创建私有仓库持久卷
1 [OSEv3:vars]2 openshift_hosted_registry_storage_kind=nfs #定义OCP存储后端
3 openshift_hosted_registry_storage_access_modes=['ReadWriteMany'] #定义访问模式,默认为ReadWriteMany,表示允许多个节点以读写形式挂载
4 openshift_hosted_registry_storage_nfs_directory=/exports #定义NFS服务器上的NFS存储目录
5 openshift_hosted_registry_storage_nfs_options='*(rw,root_squash)' #定义存储卷的NFS选项。这些选项被添加到/etc/ exports.d/openshift-ansible.exports中。rw选项允许对NFS卷进行读写访问,root_squash选项阻止远程连接的根用户拥有root特权,并为nfsnobody分配用户ID
6 openshift_hosted_registry_storage_volume_name=registry #定义要用于持久仓库的NFS目录的名称
7 openshift_hosted_registry_storage_volume_size=40Gi #定义持久卷大小
8 ... output omitted ...
9 [nfs]
10 services.lab.example.com
1 [student@workstation ~]$ oc describe pv registry-volume2 Name: registry-volume #定义持久卷名
3 Labels: <none>
4 Annotations: pv.kubernetes.io/bound-by-controller=yes
5 StorageClass:
6 Status: Bound
7 Claim: default/registry-claim #定义使用持久卷的声明
8 Reclaim Policy: Retain #默认持久卷策略,具有Retain策略的卷在从其声明中释放后不会被擦除
9 Access Modes: RWX #定义持久卷的访问模式,由Ansible inventory文件的openshift_hosted_registry_storage_access_modes=['ReadWriteMany']变量定义
10 Capacity: 40Gi #定义持久卷的大小,由Ansible inventory文件的openshift_hosted_registry_storage_volume_size变量定义
11 Message:
12 Source: #定义存储后端的位置和NFS共享
13 Type: NFS (an NFS mount that lasts the lifetime of a pod)
14 Server: services.lab.example.com
15 Path: /exports/registry
16 ReadOnly: false
17 Events: <none>
1 [user@demo ~] oc describe dc/docker-registry | grep -A4 Volumes2 Volumes:
3 registry-storage:
4 Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
5 ClaimName: registry-claim
6 ReadOnly: false
1 [user@demo ~] ssh root@master ls -l \2 /var/export/registryvol/docker/registry/v2/repositories/default/
四 PV综合实验
4.1 前置准备
4.2 本练习准备
4.3 配置NFS
1 [root@services ~]# less -FiX /root/DO280/labs/storage-review/config-review-nfs.sh2 [root@services ~]# /root/DO280/labs/storage-review/config-review-nfs.sh #创建NFS
3 [root@services ~]# showmount -e #确认验证
4.4 创建持久卷
1 [student@workstation ~]$ oc login -u admin -p redhat https://master.lab.example.com2 [student@workstation ~]$ less -FiX /home/student/DO280/labs/storage-review/review-volume-pv.yaml
3 apiVersion: v1
4 kind: PersistentVolume
5 metadata:
6name: review-pv
7 spec:
8 capacity:
9 storage: 3Gi
10 accessModes:
11 - ReadWriteMany
12 nfs:
13path: /var/export/review-dbvol
14 server: services.lab.example.com
15 persistentVolumeReclaimPolicy: Recycle
16 [student@workstation ~]$ oc create -f /home/student/DO280/labs/storage-review/review-volume-pv.yaml
17 [student@workstation ~]$ oc get pv #查看PV
18 NAME CAPACITYACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
19 review-pv 3Gi RWX Recycle Available 13s
4.5 部署模板
1 [student@workstation ~]$ less -FiX /home/student/DO280/labs/storage-review/instructor-template.yaml2 [student@workstation ~]$ oc create -n openshift -f /home/student/DO280/labs/storage-review/instructor-template.yaml
3#使用模板创建应用至openshift namespace中
4.6 创建项目
1 [student@workstation ~]$ oc login -u developer -p redhat https://master.lab.example.com2 [student@workstation ~]$ oc new-project instructor
4.7 web部署应用
4.8 端口转发
1 [student@workstation ~]$ oc login -u developer -p redhat https://master.lab.example.com2 [student@workstation ~]$ oc get pod
3 NAME READY STATUS RESTARTS AGE
4 instructor-1-9fmct 1/1 Running 0 43s
5 instructor-1-build 0/1 Completed 0 2m
6 mysql-1-f7rrq 1/1 Running 0 2m
7 [student@workstation ~]$ oc port-forward mysql-1-f7rrq 3306:3306
4.9 填充数据库
1 [student@workstation ~]$ mysql -h127.0.0.1 -u instructor -ppassword \2 instructor < /home/student/DO280/labs/storage-review/instructor.sql
3 [student@workstation ~]$ mysql -h127.0.0.1 -u instructor -ppassword instructor -e "select * from instructors;" #查看
4
4.10 测试访问
4.11 测试添加数据
4.12 确认验证
1 [student@workstation ~]$ lab storage-review grade #环境脚本判断实验
4.13 清理删除
1 [student@workstation ~]$ oc login -uadmin -predhat2 [student@workstation ~]$ oc delete project instructor
3 [student@workstation ~]$ oc delete pv review-pv
4 [student@workstation ~]$ ssh root@services
5 [root@services ~]# rm -rf /var/export/review-dbvol
6 [root@services ~]# rm -f /etc/exports.d/review-dbvol.exports
以上是 006.OpenShiefc局部性存储点 的全部内容, 来源链接: utcz.com/a/61106.html