We want to deploy Key cloak in GCP Cloud Run.
Is Key cloak suitable to run on GCP Cloud Run? Keycloak’s database will be in Cloud SQL (MySQL).
when we are trying to run key cloak docker image in GCP Cloud Run we are getting below error:
2023-03-31 12:10:15,740 WARN [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread: keycloak-default) HHH000342: Could not obtain connection to query metadata: java.sql.SQLException: Acquisition timeout while waiting for new connection
change database details in conf/keycloak.conf file and map the VM ip to domain name
add the SSL certs to that code and add domain name and certs in keycloak.conf file
use below docker file:
FROM adoptopenjdk/openjdk11
RUN mkdir -p /app
WORKDIR /app
COPY . /app
EXPOSE 8443
EXPOSE 3306
CMD [ “./keycloak-21.0.1/bin/kc.sh”, “start --optimized” ]
run the image in 8443:8443 ports
It will work perfectly in docker installed compute engine but not in cloudrun
below is the keycloak.conf file:
Basic settings for running in production. Change accordingly before deploying the server.
Database
The database vendor.
#db=postgres
db=mysql
The username of the database user.
#db-username=keycloak
db-username=keycloak
The password of the database user.
#db-password=password
db-password=keycloak.123
The full database JDBC URL. If not provided, a default URL is set based on the selected database vendor.
I successfully deploy my keycloak 21 into cloud run but with some constraints (i’m currently facing to others issues but my keycloak is able to run correctly for now)
You can not use Cloud SQL Proxy for the communication between Keycloak and Postgres ; your cloud run instance need to be set with a shared vpc ; your cloud sql instance needs to be set with this shared vpc too : Connecting to Private CloudSQL from Cloud Run | Google Codelabs