skip to Main Content

I have deployed my application on Cloud Run. It is a Laravel application and there is no problem locally. However, on the Cloud Run I get 502 bad gateway only in the first request. I think, cloud run cannot run the container and respond in time. I was wondering whether it is possible to extend the timeout and await the container to begin. I could not find any.

2

Answers


  1. Chosen as BEST ANSWER

    I fixed the problem after @JohnHanley's respond. I checked the supervisord and I was starting nginx before php-fpm and since there is nothing that can respond to the request it was returning 502 on the first request. I changed the order and put nginx at the end and it fixed the problem. Thanks for the tip @JohnHanley.


  2. For the ingress container (nginx in this case), you can add a dependency, meaning that it will wait for its dependency container to start before starting itself.

    Edit: Actually, you need to add a health check to the dependency container, otherwise the proxy will indeed start after the frontend, but will not wait for it to finish loading. If you want to make sure the proxy waits for the frontend container to finish loading, add a health check that verifies that (you can find it under the container menu towards the bottom). Read more here about sidecar container ordering.

    Look for "Container startup order > depends on" in the console UI when creating/editing a service on Cloud Run.

    Alternatively, you can run a gcloud command with the --depends on flag. Note the order of commands here is important!

    Example

    gcloud beta run deploy my-frontend 
    --platform=managed 
    --allow-unauthenticated 
    --region=europe-west1 
    --max-instances=4 
    --container my-proxy 
    --image="europe-west1-docker.pkg.dev/my-project/my-proxy/my-proxy:latest" 
    --port=8080 
    --depends-on=my-frontend 
    --container my-frontend 
    --image="europe-west1-docker.pkg.dev/my-project/my-frontend/my-frontend:latest"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search