0
0
GCPcloud~5 mins

Storage classes (Standard, Nearline, Coldline, Archive) in GCP - Commands & Configuration

Choose your learning style9 modes available
Introduction
Cloud storage offers different classes to save money based on how often you access your data. These classes help you choose the right balance between cost and speed for storing files.
When you need fast access to files you use every day, like website images or app data.
When you want to store backups that you access less than once a month but still need quickly.
When you have data you rarely access, like old project files, but want to keep them available.
When you want to archive data for years, like compliance records, and can wait hours to retrieve it.
When you want to save money by moving data to cheaper storage based on how often you use it.
Config File - bucket-config.yaml
bucket-config.yaml
apiVersion: storage.cnrm.cloud.google.com/v1beta1
kind: StorageBucket
metadata:
  name: example-bucket
spec:
  location: US
  storageClass: NEARLINE
  versioning:
    enabled: true

This file creates a Google Cloud Storage bucket named example-bucket in the US region.

The storageClass is set to NEARLINE, which means the bucket is optimized for data accessed less than once a month.

Versioning is enabled to keep older versions of objects for safety.

Commands
Create a new Google Cloud Storage bucket named example-bucket in the US region with the Nearline storage class for less frequent access.
Terminal
gsutil mb -c nearline -l US gs://example-bucket/
Expected OutputExpected
Creating gs://example-bucket/...
-c nearline - Sets the storage class to Nearline for cost-effective storage of infrequently accessed data.
-l US - Specifies the bucket location as the US region.
List detailed information about the example-bucket to verify its storage class and settings.
Terminal
gsutil ls -L gs://example-bucket/
Expected OutputExpected
Bucket: gs://example-bucket/ Location constraint: US Storage class: NEARLINE Versioning enabled: True
Upload a file named sample-file.txt to the example-bucket to store it using the Nearline class.
Terminal
gsutil cp sample-file.txt gs://example-bucket/
Expected OutputExpected
Copying file://sample-file.txt [Content-Type=text/plain]... / [1 files][ 12.0 B/ 12.0 B] Operation completed over 1 objects.
Check if there is a lifecycle policy set on the bucket to automatically change storage classes or delete objects.
Terminal
gsutil lifecycle get gs://example-bucket/
Expected OutputExpected
No lifecycle configuration found.
Key Concept

If you remember nothing else from this pattern, remember: choose a storage class based on how often you need to access your data to save money and keep performance balanced.

Common Mistakes
Creating a bucket without specifying the storage class.
The bucket defaults to Standard class, which can cost more if you don't need frequent access.
Always specify the storage class with the -c flag when creating a bucket to match your access needs.
Using Nearline or colder classes for data accessed daily.
Accessing data frequently in these classes leads to higher retrieval costs and slower access times.
Use Standard class for data you access often to avoid extra costs and delays.
Not verifying bucket settings after creation.
You might think the bucket has the right class or versioning, but it could be misconfigured.
Run gsutil ls -L to check bucket details and confirm settings.
Summary
Create a bucket with gsutil mb specifying the storage class and location.
Verify the bucket's storage class and settings with gsutil ls -L.
Upload files to the bucket to store them in the chosen class.
Check lifecycle policies to manage automatic transitions or deletions.