0
0
GCPcloud~5 mins

Deploying workloads in GCP - Commands & Configuration

Choose your learning style9 modes available
Introduction
Deploying workloads means putting your app or service on Google Cloud so it can run and be used by others. This process helps you move your code from your computer to the cloud where it can work continuously and handle users.
When you want to run a web app on Google Cloud for users to access anytime.
When you need to launch a background job that processes data regularly.
When you want to update your app with new features and make it live.
When you want to test your app in the cloud before sharing it widely.
When you want to scale your app automatically based on user demand.
Config File - app.yaml
app.yaml
runtime: python39
entrypoint: gunicorn -b :$PORT main:app

handlers:
- url: /static
  static_dir: static/

- url: /.*
  script: auto

This file tells Google App Engine how to run your Python app.

  • runtime: Specifies the Python version.
  • entrypoint: Command to start your app server.
  • handlers: Define how URLs are handled, like serving static files.
Commands
This command uploads your app configuration and code to Google Cloud and starts the deployment process.
Terminal
gcloud app deploy app.yaml
Expected OutputExpected
Services to deploy: descriptor: app.yaml Do you want to continue (Y/n)? Y Beginning deployment... Updating service [default]... Waiting for operation to complete... Deployed service [default] to [https://PROJECT_ID.uc.r.appspot.com] You can stream logs from the command line by running: gcloud app logs tail -s default
This command opens your deployed app in the web browser so you can see it running live.
Terminal
gcloud app browse
Expected OutputExpected
Launching default service in default browser...
This command shows the live logs of your app, helping you see what is happening and catch errors.
Terminal
gcloud app logs tail -s default
Expected OutputExpected
2024-06-01 12:00:00 default[20230601t123456] INFO Starting gunicorn 20.1.0 2024-06-01 12:00:05 default[20230601t123456] INFO Listening on port 8080
-s - Specifies the service name to show logs for
Key Concept

If you remember nothing else from this pattern, remember: deploying workloads means sending your app and its instructions to Google Cloud so it can run and serve users.

Common Mistakes
Not creating or updating the app.yaml file before deployment
Without this file, Google Cloud does not know how to run your app, so deployment fails or the app does not work correctly.
Always create a valid app.yaml file with the correct runtime and entrypoint before deploying.
Not confirming the deployment prompt by typing Y
The deployment stops if you do not confirm, so your app is not uploaded or updated.
Type Y and press Enter when asked to continue deployment.
Trying to browse the app before deployment finishes
The app URL is not ready until deployment completes, so the browser shows an error.
Wait for the deployment command to finish successfully before opening the app.
Summary
Create an app.yaml file to tell Google Cloud how to run your app.
Use 'gcloud app deploy app.yaml' to upload and start your app in the cloud.
Use 'gcloud app browse' to open your live app and 'gcloud app logs tail -s default' to see its logs.