Revision garbage collection

The config-gc ConfigMap contains settings that determine in-active revisions are cleaned up. This ConfigMap is located in the knative-serving namespace.

Cluster-wide configuration

The following properties allow you to configure revision garbage collection:

NameDescription
retain-since-create-timeDuration since creation before considering a revision for GC or “disabled”
retain-since-last-active-timeDuration since active before considering a revision for GC or “disabled”
min-non-active-revisionsMinimum number of non-active revisions to retain.
max-non-active-revisionsMaximum number of non-active revisions to retain or “disabled” to disable any maximum limit.

Revisions are retained if they belong to any one of the following categories:

  • Is active and is being reference by a route
  • Created within retain-since-create-time
  • Last referenced by a route within retain-since-last-active-time
  • There are fewer than min-non-active-revisions

Examples

Immediately collect any inactive revision

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-gc
  5. namespace: knative-serving
  6. data:
  7. min-non-active-revisions: "0"
  8. retain-since-create-time: "disabled"
  9. retain-since-last-active-time: "disabled"

Keep around the last ten non-active revisions

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-gc
  5. namespace: knative-serving
  6. data:
  7. retain-since-create-time: "disabled"
  8. retain-since-last-active-time: "disabled"
  9. max-non-active-revisions: "10"

Disable garbage collection

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-gc
  5. namespace: knative-serving
  6. data:
  7. retain-since-create-time: "disabled"
  8. retain-since-last-active-time: "disabled"
  9. max-non-active-revisions: "disabled"

Complex example

The following example configuration keeps recently deployed or active revisions, always maintains the last two revisions in case of rollback, and prevents burst activity from exploding the count of old revisions:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-gc
  5. namespace: knative-serving
  6. data:
  7. retain-since-create-time: "48h"
  8. retain-since-last-active-time: "15h"
  9. min-non-active-revisions: "2"
  10. max-non-active-revisions: "1000"

Per-revision options

You can configure a revision so that it is never garbage collected by adding the serving.knative.dev/no-gc: "true" annotation:

  1. apiVersion: serving.knative.dev/v1
  2. kind: Revision
  3. metadata:
  4. annotations:
  5. serving.knative.dev/no-gc: "true"
  6. spec:
  7. ...