This page shows you how to set object lifecycle policy for Google Distributed Cloud (GDC) air-gapped storage buckets.
Before you begin
A project namespace manages bucket resources in the Management API server. You must have a project to work with buckets and objects.
You must also have the appropriate bucket permissions to perform the following operation. See Grant bucket access.
Set object lifecycle policy on bucket
You can use object lifecycle policy to automatically manage objects in your buckets. This helps you store data more efficiently throughout its lifespan. A lifecycle configuration is a list of rules to expire a group of objects based on certain matching criteria.
You can create a bucket with or without object lifecycle policy. And you can apply new, update existing or remove existing lifecycle policy after the bucket is created.
For unversioned buckets, expiration means permanently removing the object asynchronously.
For versioned buckets, if the current object version is not a deletion marker, expiration makes the current version noncurrent and then adds a delete marker to the current version.
To set and modify the object lifecycle policy,
update the Bucket.spec.bucketPolicy.lifecyclePolicy field.
CLI
The following are few examples of bucket resources with different object lifecycle policy configured:
apiVersion: object.gdc.goog/v1
kind: Bucket
metadata:
name: BUCKET_NAME
namespace: NAMESPACE_NAME
spec:
description: "Bucket with lifecycle rule to expire all objects after 365 days"
storageClass: Standard
bucketPolicy:
lifecyclePolicy:
enable: true
lifecycleRules:
- expiration:
days: 365
id: expire-all-after-365-days
status: Enabled
----------
apiVersion: object.gdc.goog/v1
kind: Bucket
metadata:
name: BUCKET_NAME
namespace: NAMESPACE_NAME
spec:
description: "Bucket with lifecycle rule to expire objects in the logs/ directory after 30 days"
storageClass: Standard
bucketPolicy:
lifecyclePolicy:
enable: true
lifecycleRules:
- expiration:
days: 30
id: expire-logs-dir-after-30-days
status: Enabled
filter:
prefixFilter: "logs/"
----------
apiVersion: object.gdc.goog/v1
kind: Bucket
metadata:
name: BUCKET_NAME
namespace: NAMESPACE_NAME
spec:
description: "Bucket with lifecycle rule to expire objects having specific tag after 30 days"
storageClass: Standard
bucketPolicy:
lifecyclePolicy:
enable: true
lifecycleRules:
- expiration:
days: 30
id: expire-tagged-objects-after-30-days
status: Enabled
filter:
tagFilters:
- key: environment
value: dev
----------
apiVersion: object.gdc.goog/v1
kind: Bucket
metadata:
name: BUCKET_NAME
namespace: NAMESPACE_NAME
spec:
description: "Bucket with lifecycle rule to expire noncurrent versions after 90 days"
storageClass: Standard
bucketPolicy:
lifecyclePolicy:
enable: true
lifecycleRules:
- noncurrentExpiration:
noncurrentDays: 90
id: expire-noncurrent-after-90-days
status: Enabled
----------
apiVersion: object.gdc.goog/v1
kind: Bucket
metadata:
name: BUCKET_NAME
namespace: NAMESPACE_NAME
spec:
description: "Bucket with lifecycle rule to expire objects on a specific date"
storageClass: Standard
bucketPolicy:
lifecyclePolicy:
enable: true
lifecycleRules:
- expiration:
date: "2027-01-01T00:00:00Z"
id: expire-on-specific-date
status: Enabled
----------
apiVersion: object.gdc.goog/v1
kind: Bucket
metadata:
name: BUCKET_NAME
namespace: NAMESPACE_NAME
spec:
description: "Bucket with multiple lifecycle rules and advanced filters"
storageClass: Standard
bucketPolicy:
lifecyclePolicy:
enable: true
lifecycleRules:
# Rule 1: Expire objects in 'tmp/' directory AND tagged with 'status=ready' after 7 days
- expiration:
days: 7
id: expire-ready-tmp-objects
status: Enabled
filter:
prefixFilter: "tmp/"
tagFilters:
- key: status
value: ready
# Rule 2: Expire all objects in 'logs/' directory after 90 days
- expiration:
days: 90
id: expire-logs-after-90-days
status: Enabled
filter:
prefixFilter: "logs/"
Any updates to the lifecycle policy applies to the existing objects and objects uploaded after the update.
When the bucket also has object locking configured, objects are being protected from expiration before the retention days end.