0
0
GCPcloud~5 mins

Why Cloud Storage matters for object data in GCP - Why It Works

Choose your learning style9 modes available
Introduction
Storing files like photos, videos, or backups can be tricky because they can be very large and need to be accessed from anywhere. Cloud Storage solves this by keeping these files safe and easy to reach over the internet.
When you want to save large files like videos or images that many people can access anytime.
When you need to back up important data without using your computer's storage.
When you want to share files with your team or customers without sending emails.
When you build an app that needs to store user uploads like profile pictures or documents.
When you want to keep data safe and automatically copied in different places to avoid losing 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: STANDARD
  versioning:
    enabled: true
  lifecycle:
    rule:
      - action:
          type: Delete
        condition:
          age: 365
  labels:
    environment: dev
    team: analytics

This file creates a Cloud Storage bucket named example-bucket in the US region with standard storage class.

Versioning is enabled to keep old copies of files in case you need to restore them.

A lifecycle rule deletes files older than 365 days to save space and cost.

Labels help organize and identify the bucket by environment and team.

Commands
This command creates a new Cloud Storage bucket named example-bucket in the US region with standard storage class and enables versioning to keep old file versions.
Terminal
gcloud storage buckets create example-bucket --location=US --storage-class=STANDARD --versioning
Expected OutputExpected
Created gs://example-bucket/
--location - Sets the geographic location of the bucket
--storage-class - Defines the storage type balancing cost and access speed
--versioning - Keeps previous versions of objects for recovery
This command shows details about the example-bucket to verify its settings like location, storage class, and versioning status.
Terminal
gcloud storage buckets describe example-bucket
Expected OutputExpected
name: projects/_/buckets/example-bucket location: US storageClass: STANDARD versioning: enabled: true
This command applies a lifecycle rule to the bucket to automatically delete files older than one year, helping manage storage costs.
Terminal
gsutil lifecycle set bucket-lifecycle.json gs://example-bucket
Expected OutputExpected
No output (command runs silently)
This command retrieves and shows the lifecycle rules currently set on the bucket to confirm the automatic deletion policy.
Terminal
gsutil lifecycle get gs://example-bucket
Expected OutputExpected
{ "rule": [ { "action": {"type": "Delete"}, "condition": {"age": 365} } ] }
Key Concept

If you remember nothing else from this pattern, remember: Cloud Storage safely keeps your files accessible from anywhere and manages them automatically to save space and cost.

Common Mistakes
Creating a bucket without specifying the location
The bucket will be created in a default location that might cause slower access or higher costs.
Always specify the location flag to choose a region close to your users or services.
Not enabling versioning on the bucket
You risk losing previous versions of files if they are accidentally deleted or overwritten.
Enable versioning to keep backups of your files automatically.
Forgetting to set lifecycle rules for old files
Old files accumulate and increase storage costs unnecessarily.
Set lifecycle rules to delete or archive files after a certain time.
Summary
Create a Cloud Storage bucket with location, storage class, and versioning to store files safely.
Use commands to check bucket details and confirm settings.
Apply lifecycle rules to manage storage costs by automatically deleting old files.