Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 472 of 8027. Package Management and AutomationFree lesson

Implementing Lifecycle Policies for Stale Charts

Define and enforce retention policies within your registry to prune outdated or deprecated chart versions while preserving production history.

In this lesson, you will learn how to automate the cleanup of your OCI-compliant registry to prevent stale, unused chart versions from consuming storage and cluttering your repository.

The Problem of Chart Proliferation

As your CI/CD pipelines automate the versioning and pushing of charts, your registry can quickly become bloated with hundreds of development, feature-branch, or deprecated versions. While semantic versioning ensures your production releases remain immutable, keeping every single build artifact indefinitely is rarely necessary and increases costs and latency when fetching indices.

Defining Retention Strategies

To manage this, we implement lifecycle policies directly within your OCI-compliant registry (such as Harbor, ECR, or Artifactory). A lifecycle policy defines criteria for automatically deleting images and charts based on age, count, or tags.

For example, a typical retention policy for a Helm chart repository might look like this:

  • Keep all production releases: Match versions using a regex like v[0-9]+\.[0-9]+\.[0-9]+.
  • Retain last N versions: Keep the 5 most recent versions of any non-production (e.g., feature-*) charts.
  • Delete older than X days: Remove any non-production chart versions older than 30 days that are not tagged as "latest" or "stable."

Implementing in the Registry

Most modern registries allow you to define these rules via a JSON configuration or a UI-based dashboard. If you were defining a policy for a registry like Harbor, the rule configuration would target the specific project containing your charts:

{
  "rules": [
    {
      "action": "delete",
      "template": "latest",
      "params": "{\"count\": 5}",
      "tag_selectors": [{"kind": "glob", "pattern": "feat-*"}]
    },
    {
      "action": "delete",
      "template": "n_days_since_last_push",
      "params": "{\"n\": 30}",
      "tag_selectors": [{"kind": "none"}]
    }
  ]
}

By enforcing these policies, you guarantee that your registry remains a high-performance source of truth, ensuring developers always find the relevant versions while maintaining the immutable history required for production audits.

Key Takeaway: Implement automated retention policies based on semantic versioning and age to prune stale charts, keeping your registry lean without sacrificing production stability.