Running Keycloak production on DigitalOean

Hi! After using KC locally for a while in development I’m trying to set up Keycloak on Digital Ocean.

I built and push this Dockerfile to my container registry.

FROM quay.io/keycloak/keycloak:18.0.0 as builder
ENV KC_DB="postgres"
ENV KC_FEATURES="admin2,token-exchange"
ENV KC_HEALTH_ENABLED="true"
ENV KC_METRICS_ENABLED="true"
RUN /opt/keycloak/bin/kc.sh build

FROM --platform=linux/amd64 quay.io/keycloak/keycloak:18.0.0
COPY --from=builder /opt/keycloak/lib/quarkus/ /opt/keycloak/lib/quarkus/
ENV KC_DB_SCHEMA="public"
ENV KC_PROXY="edge"

ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]
CMD ["start"]

And I am running building and running with these additional parameters.

  • KC_DB_URL=${my-database-id.JDBC_DATABASE_URL}
  • KC_HOSTNAME=${APP_DOMAIN}
  • KEYCLOAK_ADMIN=andrew
  • KEYCLOAK_ADMIN_PASSWORD=xxx

The tables and default admin has been correctly created.

But when trying to access the Admin UI I get some errors.

Login attempt timed out

Most of the time the login window will tell me Your login attempt timed out. Login will start from the beginning.

The Admin UI keeps loading

Every sometimes I do get in and the UI keeps loading, with a bunch of 401 errors in the browsers network tab.

Failed to initialize

Sometimes the UI starts loading but an HTML alert box pops up saying keycloak failed to initialize, with a bunch of 401 errors in the browsers network tab.

At one point I managed to create, through all the errors, a Realm! So most the moving parts are actually functional. Still the UI is almost entirely non-functional.

127.0.0.1

Sometimes between all the network calls there’s calls to localhost. That makes no sense.

Reverse proxy

For all the documentation I got through I managed to understand and implement mostly everything, except reverse proxy configuration. The proxy is configured to edge (KC_PROXY=edge) and DigitalOcean handles the HTTPS. I searched for ways to configure the proxy but didn’t find anything actionable.

I might just need to switch providers where I have better control over this. I’m not sure, and wary to restart elsewhere as I spent all day on this already :slight_smile:

Any input would be greatly appreciated! :yellow_heart:

note: I had screenshots to visualize all the different issues but wasn’t allowed to post them which TBH is not ideal

It’s been fixed.

My issue was that the hosting setup was scaled to 2 running instances. Not sure if this was by default or if I set the mistaken configuration.

If you run into this scale your server down to 1 instance or go through the cluster configuration to configure your setup correctly.

1 Like