1.将/registry数据导出
mkdir /export/registry_bak
oc get pods
docker-registry-2-4qcr6
[root@master1 registry_bak]# oc rsync docker-registry-1-91s28:/registry .
2.使用NFS,创建pv和pvc
mkdir -p /export/pv/docker_registry
yum install nfs-utils rpcbind -y
chown -R nfsnobody:nfsnobody /export/pv/
systemctl restart rpcbind
[root@master1 ~]# systemctl enable rpcbind
exportfs -r
systemctl restart nfs-server
echo "/export/pv/docker_registry/ *(rw,sync,all_squash)" >> /etc/exports
mkdir /opt/pv/
[root@master1 ~]# setenforce 0
3.创建pv
[root@master1 pv]# cat pv.json
{
"apiVersion": "v1",
"kind": "PersistentVolume",
"metadata": {
"name": "registrypv"
},
"spec": {
"capacity": {
"storage": "100Gi"
},
"accessModes": [ "ReadWriteOnce" ],
"nfs": {
"path": "/export/pv/docker_registry",
"server": "192.168.10.110"
},
"persistentVolumeReclaimPolicy": "Retain"
}
}
[root@master1 pv]# oc create -f pv.json
persistentvolume "registrypv" created
给pv添加标签
[root@master1 pv]# oc label pv registrypv disktype=registry
4.创建PVC
[root@master1 pv]# cat registry_pvc.json
{
"apiVersion": "v1",
"kind": "PersistentVolumeClaim",
"metadata": {
"name": "docker-registry-claim"
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"selector": {
"matchLabels": {
"disktype": "registry"
}
},
"resources": {
"requests": {
"storage": "100Gi"
}
}
}
}
[root@master1 pv]# oc create -f registry_pvc.json
persistentvolumeclaim "docker-registry-claim" created
6.将备份的数据恢复到创建的NFS目录 #########################关键地点---registry目录下的./* -->
[root@master1 ~]# cd /export/
[root@master1 export]# mv registry_bak/registry/* pv/docker_registry/
[root@master1 export]# ls pv/docker_registry/
docker
[root@master1 export]# chown -R nfsnobody:nfsnobody /export/
7.为registry添加持久化卷请求,并与挂载点关联
oc volumes dc/docker-registry --add --name=registry-storage -t pvc --claim-name=docker-registry-claim --overwrite
参考:https://www.cnblogs.com/dukuan/p/8735017.html