zoukankan      html  css  js  c++  java
  • Harbor磁盘爆满,执行垃圾回收清理镜像

    #!/bin/bash
    set -e
    set -u
    
    # check disk
    df -h | grep data
    
    # stop harbor
    docker-compose -f /opt/harbor/docker-compose.yml down
    
    # setting harbor
    mv /opt/harbor/docker-compose.yml /opt/harbor/docker-compose.yml.common
    mv /opt/harbor/docker-compose.yml.clear /opt/harbor/docker-compose.yml
    
    mv /opt/harbor/common/config/registry/config.yml /opt/harbor/common/config/registry/config.yml.common
    mv /opt/harbor/common/config/registry/config.yml.clear /opt/harbor/common/config/registry/config.yml
    
    # start harbor
    docker-compose -f /opt/harbor/docker-compose.yml up -d
    
    # waiting healthy
    while [[ ! $(docker ps | grep -w healthy) ]]
    do
      echo "waiting healthy, sleep 3s..."
      sleep 3
    done
    
    # clear
    docker run --network="host" -it -v /data/registry:/registry -e REGISTRY_URL=http://127.0.0.1:5000 mortensrasmussen/docker-registry-manifest-cleanup:1.1.2beta
    
    docker run -it --name gc --rm --volumes-from registry vmware/registry-photon:v2.6.2-v1.4.0 garbage-collect /etc/registry/config.yml
    
    # stop harbor
    docker-compose -f /opt/harbor/docker-compose.yml down
    
    # restore harbor
    mv /opt/harbor/docker-compose.yml /opt/harbor/docker-compose.yml.clear
    mv /opt/harbor/docker-compose.yml.common /opt/harbor/docker-compose.yml
    
    mv /opt/harbor/common/config/registry/config.yml /opt/harbor/common/config/registry/config.yml.clear
    mv /opt/harbor/common/config/registry/config.yml.common /opt/harbor/common/config/registry/config.yml
    
    # start harbor
    docker-compose -f /opt/harbor/docker-compose.yml up -d
    
    # waiting healthy
    while [[ ! $(docker ps | grep -w healthy) ]]
    do
      echo "waiting healthy, sleep 3s..."
      sleep 3
    done
    
    # check disk
    df -h | grep data

    1. 我的Harbor是安装在/opt/harbor目录下,所以建立脚本的时候注意按照自己的部署环境进行调整

    2. 可以考虑放在cron定时任务中:0 0 * * * /opt/harbor/clean.sh,“/opt/harbor/clean.sh”即为刚刚建立的脚本,每天凌晨0点开始执行

    备注:

    /opt/harbor/docker-compose.yml.clear在原本的docker-compose.yml中增加了(加粗部分):

    registry:
      image: goharbor/registry-photon:v2.7.1-patch-2819-2553-v1.9.3
      container_name: registry
      (省略部分代码...)
      ports:
        - 127.0.0.1:5000:5000
      (省略部分代码...)

    /opt/harbor/common/config/registry/config.yml.clear在原本的config.yml中注释掉了(加粗部分):

    http:
      addr: :5000
      secret: placeholder
      debug:
        addr: localhost:5001
    #auth:
    #  token:
    #    issuer: harbor-token-issuer
    #    realm: http://registry.bocloud.com.cn/service/token
    #    rootcertbundle: /etc/registry/root.crt
    #    service: harbor-registry
    validation:
      disabled: true
    (省略部分代码...)
    笔者只是初学者,开此博客的初衷是为了给自己的学习过程留一个痕迹。所以您可能发现笔者措辞不严谨、逻辑不合理,甚至代码有错误、结论很偏颇等等。笔者感激各位的讨论和指正,并在此不胜感激!拜谢!欢迎加QQ群讨论:852410026
  • 相关阅读:
    python 学习
    快速排序
    U3D AStar 案例
    U3D AStar 算法原理
    .net core 实时通讯
    .net 算法复杂度
    U3D MVC 背包案例
    U3D 对象池
    Unity网络基础(NetWork)
    U3D Socket实现简易通讯
  • 原文地址:https://www.cnblogs.com/LOVE0612/p/15063425.html
Copyright © 2011-2022 走看看