Soru

Zorluk: ZorDeploying Serverless Applications with Cloud Run and Cloud Functions

A developer packaged a Node.js REST API into a container image where the application server strictly listens on internal TCP port 8000 without reading the PORT environment variable. When deploying this container image to Google Cloud Run using the standard gcloud CLI command, deployment fails because startup health checks time out. How should the developer configure the deployment to successfully serve traffic on Cloud Run without modifying the application source code?

  1. A
    Set the deployment environment variable using `--set-env-vars=PORT=8080` in the gcloud run deploy command.
  2. B
    Re-deploy the container image using `gcloud functions deploy` with the `--trigger-http` flag.
  3. Include the `--port=8000` flag during the `gcloud run deploy` command execution.Cevap
  4. D
    Grant the default compute service account the `roles/owner` primitive role across the project.

Cevap

Include the `--port=8000` flag during the `gcloud run deploy` command execution.
Cloud Run defaults to sending ingress traffic to port 8080 inside the container. When an application hardcodes listening on port 8000 and ignores the PORT environment variable, specifying `--port=8000` in `gcloud run deploy` configures Cloud Run to route traffic to port 8000, resolving health check timeouts.

Adım Adım Çözüm

1
Identify the container contract requirement for Cloud Run.
By default, Cloud Run sends HTTP requests to port 8080 inside the container and populates the PORT environment variable with 8080.
If an application does not consume the PORT environment variable and listens on a non-standard port like 8000, Cloud Run health checks targeting 8080 will time out.
2
Select the correct gcloud deployment flag to override default container port routing.
Passing `--port=8000` configures Cloud Run's ingress routing to direct requests directly to port 8000.
This allows custom legacy or third-party container images to run on Cloud Run without needing source code modifications.

Anahtar Kavram

Cloud Run Custom Container Port Binding
Bu soruyu puanla