Cleaning up the GitLab Registry for Kubernetes admins

Nowadays, in every house there is a kubernetes cluster, applications are rolled out to the cluster by the tag. The image of the deployed application is sent as a tag to the repository of the Registry GitLab project, which gradually swells to incredible sizes.





Existing solutions

  • Out of the box solution





    Settings → CI/CD → CleanUp policy for tags. , Bulk Delete , , . - , .





  • community





    1. " "





    2. .





, :





. , - , ( Job, CronJob ). , .





GitLab

GitLab registry , . , .





ron ,





sudo gitlab-ctl registry-garbage-collect
      
      







sudo gitlab-ctl registry-garbage-collect -m
      
      



: registry, push, pull.





registry readonly.





sudo vi /etc/gitlab/gitlab.rb
      
      



registry['storage'] = {
    'maintenance' => {
      'readonly' => {
        'enabled' => true
      }
    }
  }
      
      



sudo gitlab-ctl reconfigure
      
      



enabled false sudo gitlab-ctl reconfigure.





GitLab





GitLab GitLab API api + read_repository write_registry.





, registry GitLab, id id registry.





GitLab pagination

GitLab , 20 , 100 . X-Total, , .





  1. /api/v4/projects, endpoint . , id.





  2. , .





  3. project[id] /api/v4/projects/{project[id]}/registry/repositories. id .





  4. , , /api/v4/projects/{repo['project_id']}/registry/repositories/{repo['id']}/tags





, :





{
    "location": "mygitlab.abc.ru:3000/dev/my-awsome-app/base:deploy_123",
    "name": "deploy_123",
    "path": "dev/my-awsome-app/base:deploy_123"
  }
      
      



del_url, URL .





- , .





Kubernetes





Kubernetes kubernetes. , , - .





Kubernetes , kubectl rollout history < >, ReplicaSet . . , . replicaset namespace + label app replica_set.spec.template.spec.service_account. - , - . , N .





- Kubernetes, GitLab .





: Job CronJob ReplicaSet. .





, :)





" " ...





GitLab, , . .





, CronJob Job. .





Automation is written in python , but this is not so important. You can significantly reduce code size and memory costs with a little thought.








All Articles