OpenShift实战(三):OpenShift持久化存储Registry

dukuan 2018-04-07 原文

OpenShift实战(三):OpenShift持久化存储Registry

1、查看Registry组件的DC关于volume的定义 

  可以看到registry-storage这个挂载点被指向了一个/registry目录,使用的是empty directory,即数据保存在计算节点上,当registry容器重启,所在node节点产生变化,数据即丢失。

[root@master1 ~]# oc volumes dc/docker-registry --all
deploymentconfigs/docker-registry
  empty directory as registry-storage
    mounted at /registry
  secret/registry-certificates as registry-certificates
mounted at /etc/secrets

 

2、备份Registry

  查看当前使用的空间

[root@master1 ~]# oc get pods
NAME                       READY     STATUS    RESTARTS   AGE
docker-registry-1-91s28    1/1       Running   3          3d
registry-console-1-jkcg9   1/1       Running   2          3d
router-1-90m4s             1/1       Running   2          3d
router-1-gqpmw             1/1       Running   2          3d
router-1-wdkkc             1/1       Running   2          3d
[root@master1 ~]# oc rsh docker-registry-1-91s28 'du' '-sh' '/registry'
3.7G    /registry

  将/registry数据导出

[root@master1 ~]# mkdir /export/registry_bak
[root@master1 ~]# cd !$
cd /export/registry_bak
[root@master1 registry_bak]# oc rsync docker-registry-1-91s28:/registry .
receiving incremental file list
registry/
registry/docker/
registry/docker/registry/
registry/docker/registry/v2/
registry/docker/registry/v2/blobs/
registry/docker/registry/v2/blobs/sha256/
registry/docker/registry/v2/blobs/sha256/04/
registry/docker/registry/v2/blobs/sha256/04/043c1366c361738b7518f87d87071910347763605e0866b6ebba2032415cbbc8/
registry/docker/registry/v2/blobs/sha256/04/043c1366c361738b7518f87d87071910347763605e0866b6ebba2032415cbbc8/data
…
…
…
sent 12798 bytes  received 3911549556 bytes  10586095.68 bytes/sec
total size is 3910981196  speedup is 1.00
[root@master1 registry_bak]# du -sh .
3.7G    .

 

3、创建Registry持久化PV

  创建分支,此处使用NFS

[root@master1 ~]# mkdir -p /export/pv/docker_registry
[root@master1 ~]# yum install nfs-utils rpcbind -y
[root@master1 ~]# chown -R nfsnobody:nfsnobody /export/pv/
[root@master1 ~]# systemctl start rpcbind
[root@master1 ~]# systemctl enable rpcbind
[root@master1 ~]# exportfs -r
[root@master1 ~]# systemctl start nfs-server
[root@master1 ~]# systemctl enable nfs-server
[root@master1 export]# echo "/export/pv/docker_registry/  *(rw,sync,all_squash)" >> /etc/exports
[root@master1 export]# exportfs -r
[root@master1 export]# systemctl reload nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@master1 ~]# setenforce 0
[root@master1 opt]# mkdir /opt/pv/
[root@master1 opt]# cd !$

  创建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
persistentvolume "registrypv" labeled
[root@master1 pv]# oc get pv --show-labels
NAME         CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS      CLAIM     STORAGECLASS   REASON    AGE       LABELS
registrypv   100Gi      RWO           Retain          Available                                      2m        disktype=registry

  创建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

  查看PV及PVC状态

[root@master1 pv]# oc get pv
NAME         CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS    CLAIM                           STORAGECLASS   REASON    AGE
registrypv   100Gi      RWO           Retain          Bound     default/docker-registry-claim                            8m
[root@master1 pv]# oc get pvc
NAME                    STATUS    VOLUME       CAPACITY   ACCESSMODES   STORAGECLASS   AGE
docker-registry-claim   Bound     registrypv   100Gi      RWO                          54s

 

4、恢复数据

  将备份的数据恢复到创建的NFS目录

 

[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/

  registry添加持久化卷请求,并与挂载点关联

[root@master1 export]# oc volumes dc/docker-registry --add --name=registry-storage -t pvc --claim-name=docker-registry-claim --overwrite
deploymentconfig "docker-registry" updated
[root@master1 export]# oc get pods
NAME                       READY     STATUS    RESTARTS   AGE
docker-registry-1-91s28    1/1       Running   3          3d
docker-registry-2-deploy   1/1       Running   0          6s

  DC被重新定义后,openshift会创建新的容器实例。

 

  查看容器状态

[root@master1 export]# oc get pods -o wide
NAME                       READY     STATUS              RESTARTS   AGE       IP               NODE
docker-registry-1-91s28    1/1       Running             3          3d        10.130.0.4       node1.xxx.net
docker-registry-2-deploy   1/1       Running             0          2m        10.130.0.27      node1.xxx.net
docker-registry-2-t1snn    0/1       ContainerCreating   0          2m        <none>           node2.xxx.net
registry-console-1-jkcg9   1/1       Running             2          3d        10.128.0.5       node4.xxx.net
router-1-90m4s             1/1       Running             2          3d        192.168.10.113   node2.xxx.net
router-1-gqpmw             1/1       Running             2          3d        192.168.10.116   node3.xxx.net
router-1-wdkkc             1/1       Running             2          3d        192.168.10.112   node1.xxx.net

[root@master1 export]# oc get pods -o wide
NAME                       READY     STATUS    RESTARTS   AGE       IP               NODE
docker-registry-2-t1snn    1/1       Running   0          5m        10.131.0.35      node2.xxx.net
registry-console-1-jkcg9   1/1       Running   2          3d        10.128.0.5       node4.xxx.net
router-1-90m4s             1/1       Running   2          3d        192.168.10.113   node2.xxx.net
router-1-gqpmw             1/1       Running   2          3d        192.168.10.116   node3.xxx.net
router-1-wdkkc             1/1       Running   2          3d        192.168.10.112   node1.xxx.net

 

  创建成功后检查Registry大小

[root@master1 export]# oc rsh docker-registry-2-t1snn "du" "-sh"  "/registry"
3.7G    /registry
[root@master1 export]# oc volumes dc/docker-registry
deploymentconfigs/docker-registry
  pvc/docker-registry-claim (allocated 100GiB) as registry-storage
    mounted at /registry
  secret/registry-certificates as registry-certificates
mounted at /etc/secrets

 

 

 

 

 

[root@master1
registry_bak]# du -sh .

3.7G .

发表于 2018-04-07 21:29 杜先生的博客 阅读() 评论() 编辑 收藏

 

版权声明:本文为dukuan原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/dukuan/p/8735017.html

OpenShift实战(三):OpenShift持久化存储Registry的更多相关文章

  1. Openshift 4.4 静态 IP 离线安装系列:初始安装

    上篇文章准备了离线安装 OCP 所需要的离线资源,包括安装镜像、所有样例 Image Stream 和 Ope […]...

  2. 010.OpenShift综合实验及应用

    实验一 安装OpenShift 1.1 前置准备 [student@workstation ~]$ lab r […]...

  3. 008.OpenShift Metric应用

    一 METRICS子系统组件 1.1 metric架构介绍 OpenShift metric子系统支持捕获和长 […]...

  4. OpenShift实战(二):OpenShift节点扩容

    OpenShift实战(二):OpenShift节点扩容 1、新增节点信息   增加节点如下,请将xxx改为自 […]...

  5. openshift 4.3 Istio的搭建(istio 系列一)

    openshift 4.3 Istio的搭建 本文档覆盖了官方文档的Setup的所有章节 目录 openshi […]...

  6. 004.OpenShift命令及故障排查

    一 CLI访问OpenShift资源 1.1 资源操作 OCP将OpenShift集群中的为由主节点管理的对象 […]...

  7. 001.OpenShift介绍

    一 OpenShift特性 1.1 OpenShift概述 Red Hat OpenShijft Contai […]...

  8. OpenShift实战(六):OpenShift日志监控EFK

    OpenShift实战(六):OpenShift日志监控EFK 1、镜像下载   为了防止安装过程中由于镜像下 […]...

随机推荐

  1. 常见的系统架构

    一、软件架构 软件架构(software architecture)是一系列相关的抽象模式,用于指导大型软件系 […]...

  2. redis可以存储的数据类型

    一、Redis的基本知识      在学习redis之前,我们首先要对redis有一些基本的认识。我们都知道数 […]...

  3. 30个值得推荐的数据可视化工具,赶紧收藏!

    最新30个数据可视化工具,赶紧收藏,记得点赞!! 目录 1、零编程工具 图表(9个) 信息图(2个) 地图(1 […]...

  4. Linux环境下部署完JDK后运行一个简单的Java程序

    前言 前一篇文章详细讲解了如何在Windows环境下安装虚拟机+Linux系统,并且成功部署了JDK。 不过部 […]...

  5. Java ListIterator(迭代器)

      LIstIterator是一个更加强大的Iterator的子类型,它只能用于各种List类的访问,尽管It […]...

  6. .net测试篇之Moq行为配置

    系列目录 我们前面说过.Moq在创建模拟对象的时候,简单对象赋值默认值,引用对象赋值为null,但是有些时候接 […]...

  7. html 富文本编辑器相关–向编辑器内部插入文字图片等各种dom元素 通用方法

      有问题的插入方案 <!DOCTYPE html> <html lang="en"> […]...

  8. java学习第八天2020/7/13

    一. 多态的使用 public class Father { public void say() { Syst […]...

展开目录

目录导航