Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Nginx as Cloud Run sidecar container

I have a Docker image, a server that expose the 9011 port and I can't change it. As suggested by a user. I am trying using Nginx as sidecar container described here.

My Dockerfile:

FROM fusionauth/fusionauth-app:latest

ENV DATABASE_URL=${DATABASE_URL} \
DATABASE_ROOT_USERNAME=${DATABASE_USERNAME} \
DATABASE_ROOT_PASSWORD=${DATABASE_PASSWORD} \
DATABASE_USERNAME=${DATABASE_USERNAME} \
DATABASE_PASSWORD=${DATABASE_PASSWORD} \
FUSIONAUTH_APP_MEMORY=${FUSIONAUTH_APP_MEMORY} \
FUSIONAUTH_APP_RUNTIME_MODE=${FUSIONAUTH_APP_RUNTIME_MODE} \
FUSIONAUTH_APP_URL=http://localhost:9011 \
SEARCH_TYPE=database

EXPOSE 9011

nginx.conf:

server {
listen 8080;
server_name _;
gzip on;

location / {
proxy_pass http://127.0.0.1:9011;

proxy_set_header X-Forwarded-Port 443;
}

location /health_check {
access_log off;
add_header 'Content-Type' 'application/json';
return 200 '{"status":"UP"}';
}
}
I added a health_check because it is required, it does not deploy otherwise. However, it fails and the in the log i read:
STARTUP HTTP probe failed 3 times consecutively for container "nginx-proxy" on path "/health_check". The instance was not started.

This is the Health check I added:
- Probe type: HTTP
- Path: /health_check
- Port: 8080
- Initial delay: 2
- Period: 5
- Failure threshold: 3
- Timeout: 1

Any hint?

0 1 332
1 REPLY 1

Hi @Emaborsa2,

Welcome to the Google Cloud Community!

Cloud Run health checks are a mechanism to make sure Cloud Run clone instances of a revision are ready to serve traffic. Cloud Run health checks bypass upstream ingress and authentication restrictions.

Here are a few reasons that might be causing the error:

  • Issues in startup dependencies, like calls to external API/services
  • Delayed startup can cause startup probe failures
  • May also be caused by overloaded servers

Here are a few steps that might help:

  • Increase timeout and initial delay to 5s. A timeout of 5s gives the app more time to initialize before the first check.
  • Set minimum instances to 1. By enabling minimum instances, Cloud Run keeps at least the number of minimum instances running, even if they're not serving requests. This can help reduce request timeouts.
  • Perform "Container failed to start" troubleshooting. These steps may rule out the container as a possible cause for the health check error.
  • Confirm if you have a Health check endpoint created. You need to add an endpoint in your service code to respond to the startup probe, for example:

 

startupProbe:
 httpGet:
  path: /health_check

 

I hope this helps!