Skip to main content

Your first application

Think of any application within CGC as compute or database resource. It is container that runs within POD, managed by DEPLOYMENT or STATEFUL-SET.

Below example showcase quick deployment of Nginx container within CGC.

Custom Nginx application

# Import the SDK resource
import cgc.sdk.resource as resource

# Create a web server - it's like installing an app!
result = resource.resource_create(
name="my-first-app", # What you want to call it
image_name="nginx:latest", # The application to run (nginx is a web server)
cpu=1, # How many CPU cores (like computer processors)
memory=2 # How much RAM in gigabytes
)

# Check if it worked
if result['code'] == 200:
print("Success! Your web server is starting up.")
else:
print(f"Something went wrong: {result['message']}")

Using pre-existing apps

Adding entity with a valid string, allows running pre-configured images within CGC.

Nvidia Pytorch example

response = resource.resource_create(
# Required parameters
name="advanced-app", # Unique identifier

# Resource specifications
entity="nvidia-pytorch", # Entity type (default: "custom")
cpu=4, # CPU cores
memory=16, # Memory in GB
shm_size=2, # Shared memory in GB
gpu=1, # Number of GPUs
gpu_type="A5000", # GPU model
environment_data=["ENV=production", "DEBUG=false"],
)

Get entity list

# Get all available entity types
entities = resource.get_entity_list()
print("Available entities:", entities)

Available GPU types

from cgc.commands.compute.compute_models import GPUsList
print(GPUsList.get_list())

Resource allocation

Based on your needs, here are some common specification for the application that you could run:

  • Simple website: 1 CPU, 2GB memory
  • Database: 2-4 CPU, 8-16GB memory
  • Data processing: 4-8 CPU, 16-32GB memory

Listing resources

Resources are split into three types: compute, db, jobs. This part describes both compute and db.

List all compute resources

import cgc.sdk.resource as resource

# Get all compute resources
compute_resources = resource.compute_list()

# Parse the response
if compute_resources['code'] == 200:
pods = compute_resources['details']['pods_list']
for pod in pods:
if 'app-name' in pod.get('labels', {}):
name = pod['labels']['app-name']
status = pod['status']
print(f"{name}: {status}")

List all database resources

# Get all database resources
db_resources = resource.db_list()

if db_resources['code'] == 200:
for db in db_resources['details']['pods_list']:
print(f"Database: {db['labels'].get('app-name', 'unknown')}")

Troubleshooting resources

Resource won't start

  • Check image name is correct
  • Verify you have sufficient quota
  • Check startup command syntax

Can't connect to resource

  • Verify ports are configured correctly
  • Check if resource is ready
  • Ensure ingress is enabled for external access

Resource keeps restarting

  • Check logs for errors
  • Verify environment variables
  • Ensure sufficient memory allocated