• harbor资源管理垃圾回收


    1 . Harbor常用api接口应用

    [root@confluence_jira ~]# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "172.24.101.37:8885/api/projects?project_name=library"
    [
      {
        "project_id": 2,
        "owner_id": 1,
        "name": "public_opinion",
        "creation_time": "2019-01-16T06:37:40Z",
        "update_time": "2019-01-16T06:37:40Z",
        "deleted": false,
        "owner_name": "",
        "togglable": true,
        "current_user_role_id": 1,
        "repo_count": 1,
        "chart_count": 0,
        "metadata": {
          "public": "false"
        }
      },
      {
        "project_id": 1,
        "owner_id": 1,
        "name": "library",
        "creation_time": "2019-01-16T06:33:52.831689Z",
        "update_time": "2019-01-16T06:33:52.831689Z",
        "deleted": false,
        "owner_name": "",
        "togglable": true,
        "current_user_role_id": 1,
        "repo_count": 1,
        "chart_count": 0,
        "metadata": {
          "public": "true"
        }
      }
    [root@harbor ~]# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "http://192.168.138.130/api/projects/1"
    {
      "project_id": 1,
      "owner_id": 1,
      "name": "library",
      "creation_time": "2019-01-25T12:04:20.829437Z",
      "update_time": "2019-01-25T12:04:20.829437Z",
      "deleted": false,
      "owner_name": "",
      "togglable": true,
      "current_user_role_id": 1,
      "repo_count": 1,
      "chart_count": 0,
      "metadata": {
        "public": "true"
      }
    [root@harbor ~]# curl  -u "admin:Harbor12345"  -X GET -H "Content-Type: application/json" "http://192.168.138.130/api/search?q=centos"
    {
      "project": [],
      "repository": [
        {
          "project_id": 1,
          "project_name": "library",
          "project_public": true,
          "pull_count": 0,
          "repository_name": "library/centos",
          "tags_count": 1
        }
      ],
      "Chart": null
    }
    
    [root@harbor ~]# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "http://192.168.138.130/api/projects/"
    [
      {
        "project_id": 2,
        "owner_id": 1,
        "name": "public_opinion",
        "creation_time": "2019-01-25T14:17:14Z",
        "update_time": "2019-01-25T14:17:14Z",
        "deleted": false,
        "owner_name": "",
        "togglable": true,
        "current_user_role_id": 1,
        "repo_count": 0,
        "chart_count": 0,
        "metadata": {
          "public": "true"
        }
      },
      {
        "project_id": 1,
        "owner_id": 1,
        "name": "library",
        "creation_time": "2019-01-25T12:04:20.829437Z",
        "update_time": "2019-01-25T12:04:20.829437Z",
        "deleted": false,
        "owner_name": "",
        "togglable": true,
        "current_user_role_id": 1,
        "repo_count": 1,
        "chart_count": 0,
        "metadata": {
          "public": "true"
        }
      }
    [root@harbor ~]# curl -u "admin:Harbor12345" -X POST -H "Content-Type: application/json" "http://192.168.138.130/api/projects" -d @createproject.json
    [root@harbor ~]# cat createproject.json 
    {
    
      "project_name": "testrpo",
    
      "public": 0
    
    }
    curl -u "admin:Harbor12345" -X POST -H "Content-Type: application/json" "http://192.168.138.130/api/projects/{project_id}/logs/filter" -d @log.json
    [root@harbor ~]# cat log.json 
    {
    
      "username": "admin"
    
    }
    curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "http://192.168.138.130/api/users" 获取用户信息
    [root@harbor ~]# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "http://192.168.138.130/api/users/current"
    {
      "user_id": 1,
      "username": "admin",
      "email": "admin@example.com",
      "password": "",
      "realname": "system admin",
      "comment": "admin user",
      "deleted": false,
      "role_name": "",
      "role_id": 0,
      "has_admin_role": true,
      "reset_uuid": "",
      "creation_time": "2019-01-25T12:04:20.829437Z",
      "update_time": "2019-01-25T12:04:21.466614Z"
    [root@harbor ~]# curl -u "admin:Harbor12345" -X POST -H "Content-Type: application/json" "http://192.168.138.130/api/users" -d @user.json
    [root@harbor ~]# cat user.json 
    {
    
      "user_id": 5,
    
      "username": "xinju",
    
      "email": "xinju@gmail.com",
    
      "password": "Xinju12345",
    
      "realname": "xinju",
    
      "role_id": 2
    
    }
    
    [root@harbor ~]# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "http://192.168.138.130/api/users"
    [
      {
        "user_id": 3,
        "username": "xinju",
        "email": "xinju@gmail.com",
        "password": "8c9bd99bc87dbfc5168e316c770c032d",
        "realname": "xinju",
        "comment": "",
        "deleted": false,
        "role_name": "",
        "role_id": 0,
        "has_admin_role": false,
        "reset_uuid": "",
        "creation_time": "2019-01-25T14:30:06Z",
        "update_time": "2019-01-25T14:30:06Z"
      }
    
    [root@harbor ~]# curl -u "admin:Harbor12345" -X DELETE  -H "Content-Type: application/json" "http://192.168.138.130/api/users/3"
    [root@harbor ~]# curl-u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "http://192.168.138.130/api/repositories?project_id=1&q=centos"
    [
      {
        "id": 1,
        "name": "library/centos",
        "project_id": 1,
        "description": "",
        "pull_count": 0,
        "star_count": 0,
        "tags_count": 1,
        "labels": [],
        "creation_time": "2019-01-25T14:12:31.421446Z",
        "update_time": "2019-01-25T14:12:31.421446Z"
      }
    [root@harbor ~]# curl -s -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "http://192.168.138.130/api/repositories/library%2Fcentos/tags/"
    [
      {
        "digest": "sha256:20f32279b5e4801424c21f56c2f645fc2109d81bdc3cc6855e7e982b5d3d334b",
        "name": "7.2.1511",
        "size": 71563149,
        "architecture": "amd64",
        "os": "linux",
        "docker_version": "17.06.2-ce",
        "author": "The CentOS Project u003ccloud-ops@centos.orgu003e",
        "created": "2018-10-09T18:21:43.342796088Z",
        "config": {
          "labels": {
            "license": "GPLv2",
            "name": "CentOS Base Image",
            "vendor": "CentOS"
          }
        },
        "signature": null,
        "labels": []
      }

    2 .harbor 删除镜像

    [root@harbor ~]# curl -u "admin:Harbor12345" -X DELETE -H "Content-Type: application/json" http://192.168.138.130/api/repositories/library%2Fcentos/tags/7.2.1511
    
    #解释 library是项目名,centos是镜像名称,7.2.1511是镜像标签

    3 harbor垃圾回收

       a、首先,删除Harbor的UI中的存储库。这是软删除。您可以删除整个存储库或仅删除它的标签。软删除后,Harbour中不再管理存储库,但是存储库的文件仍然保留在Harbour的存储中。 

    [root@harbor ~]# curl -u "admin:Harbor12345" -X DELETE -H "Content-Type: application/json" http://192.168.138.130/api/repositories/library%2Fcentos/tags/7.2.1511

       b、接下来,使用注册表的垃圾回收(GC)删除存储库的实际文件。在执行GC之前,确保没有人推送图像或Harbour根本没有运行。如果有人在GC运行时推送镜像,则存在镜像层被错误删除的风险,从而导致镜像损坏。所以在运行GC之前,首选的方法是先停止Harbour。

    [root@harbor harbor]# docker-compose stop
    Stopping nginx              ... done
    Stopping harbor-jobservice  ... done
    Stopping harbor-portal      ... done
    Stopping harbor-core        ... done
    Stopping harbor-adminserver ... done
    Stopping registryctl        ... done
    Stopping redis              ... done
    Stopping harbor-db          ... done
    Stopping registry           ... done
    Stopping harbor-log         ... done

      c、在部署Harbour的主机上运行以下命令以预览会影响哪些文件/镜像 

           注:上述选项”–dry-run”将打印进度而不删除任何数据。

    [root@harbor ~]# docker run -it --name gc --rm --volumes-from registry vmware/registry-photon:v2.6.2-v1.5.0 garbage-collect --dry-run /etc/registry/config.yml
    Unable to find image 'vmware/registry-photon:v2.6.2-v1.5.0' locally
    v2.6.2-v1.5.0: Pulling from vmware/registry-photon
    97b915ad4ee1: Pull complete 
    7403d4fcc953: Pull complete 
    d79f0623a023: Pull complete 
    03fe7d8c1fcc: Pull complete 
    692f0a17470a: Pull complete 
    7c85caeabf8f: Pull complete 
    ef3310fc291c: Pull complete 
    Digest: sha256:3ee1c992200a069d8d943aa21f555950bd7d1764122a936ba2a3cb115885bf86
    Status: Downloaded newer image for vmware/registry-photon:v2.6.2-v1.5.0
    library/centos
    
    0 blobs marked, 3 blobs eligible for deletion
    blob eligible for deletion: sha256:20f32279b5e4801424c21f56c2f645fc2109d81bdc3cc6855e7e982b5d3d334b
    blob eligible for deletion: sha256:4cbf48630b46d315687eb42e32ff93da0197f6a6e07c010c2eb180528da80e91
    blob eligible for deletion: sha256:f2d1d709a1daed8f529e5f561d7e102c08cab4856f1ca44c36509c552d14e3fe
    [root@harbor harbor]# du -sh /data/
    128M    /data/

      d、以下命令执行垃圾回收

    [root@harbor harbor]# docker run -it --name gc --rm --volumes-from registry vmware/registry-photon:v2.6.2-v1.5.0 garbage-collect /etc/registry/config.yml
    library/centos
    
    0 blobs marked, 3 blobs eligible for deletion
    blob eligible for deletion: sha256:f2d1d709a1daed8f529e5f561d7e102c08cab4856f1ca44c36509c552d14e3fe
    INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/f2/f2d1d709a1daed8f529e5f561d7e102c08cab4856f1ca44c36509c552d14e3fe  go.version=go1.7.3 instance.id=b3425a25-da41-4049-922b-1bb3151d7ee9 service=registry
    blob eligible for deletion: sha256:20f32279b5e4801424c21f56c2f645fc2109d81bdc3cc6855e7e982b5d3d334b
    INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/20/20f32279b5e4801424c21f56c2f645fc2109d81bdc3cc6855e7e982b5d3d334b  go.version=go1.7.3 instance.id=b3425a25-da41-4049-922b-1bb3151d7ee9 service=registry
    blob eligible for deletion: sha256:4cbf48630b46d315687eb42e32ff93da0197f6a6e07c010c2eb180528da80e91
    INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/4c/4cbf48630b46d315687eb42e32ff93da0197f6a6e07c010c2eb180528da80e91  go.version=go1.7.3 instance.id=b3425a25-da41-4049-922b-1bb3151d7ee9 service=registry

      e、重启harbor各组件镜像

    [root@harbor harbor]# docker-compose start
    Starting log         ... done
    Starting postgresql  ... done
    Starting redis       ... done
    Starting adminserver ... done
    Starting registry    ... done
    Starting core        ... done
    Starting jobservice  ... done
    Starting portal      ... done
    Starting proxy       ... done
    Starting registryctl ... done
    [root@harbor harbor]# du -sh /data/
    59M    /data/

    参考:https://www.cnblogs.com/xiyangxixi/p/10126106.html 通过api接口删除镜像

    https://blog.csdn.net/kong2030/article/details/81331142 回收harbor存储资源

  • 相关阅读:
    数据库
    流式布局
    ScrollView简单用法
    ADB被占用解决办法
    安卓中shape中的属性大全
    sql语句replace into的用法
    debug
    大数据量数据库优化
    Gson解析后的数据存到本地数据库 耗时的问题
    数据同步异步加载handler Looper
  • 原文地址:https://www.cnblogs.com/Honeycomb/p/10320188.html
Copyright © 2020-2023  润新知