PodmanではじめるRed Hatのミドルウェア製品:Keycloak

Red Hatでソリューションアーキテクトをしている田中司恩(@tnk4on)です。 PodmanではじめるRed Hatのミドルウェア製品シリーズ、今回取り上げる製品は「Red Hat build of Keycloak(RHBK)」です。

(追記:続きの記事を書きました。合わせてお読みください) rheb.hatenablog.com

-目次-


Red HatがサポートするRed Hat build of Keycloakの構成

はじめに確認するのはRed Hat build of Keycloakのサポート構成です。しかしこの構成が多岐に渡るので少しややこしいです。 まずは製品ドキュメントを確認するのですが、Red Hat build of Keycloakのサポート構成の詳細についてはKCS(ArticlesやSolutions)に記載があります。 チェック頂きたいのがこの2つのリンクです。

「Red Hat build of Keycloak support on 3rd-party...」の方は日本語版が古い内容になっているので英語版をリンクしておきます

サポートされる構成をザックリ分けるとこの2つのパターンになります。

  • RHELまたはWindowsのホストの上で直接Red Hat build of Keycloakを実行するパターン
  • OpenShiftの上でコンテナとして実行するパターン

ここから話しが込み入ってくるのですが、その原因となるのが「OpenShift以外の3rdパーティ製のコンテナ/Kubernetes環境」です。 Red Hatは公式のRed Hat build of Keycloakコンテナイメージを提供していますが、これを使ってサポートされる構成は「OpenShift」で実行する場合のみです。 OpenShift以外の3rdパーティ製のコンテナ/Kubernetes環境でRed Hat提供のRed Hat build of Keycloakコンテナイメージを実行する場合はサポートされません。 また、このRed Hat提供のRed Hat build of KeycloakコンテナイメージをRHEL上のPodmanで動かしてもサポートされません。

え?このシリーズは「Podmanではじめる〜」なんですが、どうすんの?という点は後ほど回答します。 兎にも角にも「Red Hat提供のRed Hat build of KeycloakコンテナイメージがサポートされるのはOpenShiftのみ」と覚えておきましょう。

では、3rdパーティー製のコンテナ/Kuberentes環境ではRed Hat build of Keycloakが使う方法はないのか、というとそうではないのです。 3rdパーティー製のコンテナ/Kuberentes環境については、条件を合わせることで限定的なサポートを受けることができます。

要約すると下記のようなポイントがあります。

  • 3rdパーティ環境にデプロイされたRed Hatミドルウェア製品のサポートガイドラインに沿ってcommercially reasonably support(商業的に合理的なサポート)を受けることが可能
  • サポート対象のバージョンのRed Hat build of KeycloakのZIPアーカイブ、サポートされるJVM、UBIを使用してカスタムコンテナイメージをセルフビルドしたものを使用する
  • Red Hatサポートはカスタム コンテナ イメージの作成と保守を支援またはサポート行わない(必要に応じて有償のコンサルティングサービスをご購入いただけます)

Red Hat build of Keycloakのサポート構成、サポートされない構成、商業的に合理的なサポート構成をまとめると下記の図のようになります。(各コンポーネントやOSのバージョンなどは省略しています)

Red Hat build of Keycloakのサポート構成

Red Hat build of Keycloakのサポート構成
Red Hat build of Keycloakのサポート構成

Red Hat build of Keycloakのサポートされない構成

Red Hat build of Keycloakのサポートされない構成
Red Hat build of Keycloakのサポートされない構成

Red Hat build of Keycloakの商業的に合理的なサポート構成

Red Hat build of Keycloakの商業的に合理的なサポート構成
Red Hat build of Keycloakの商業的に合理的なサポート構成

本記事ではこれ以上細かい内容については解説しませんが、導入の検討において詳細な確認が必要な場合は担当のRed Hatの営業までお尋ねください。

Podmanを使ってRed Hat build of Keycloakでできること

さて、PodmanではRed Hat build of Keycloakのコンテナイメージの実行がサポートされないという衝撃の事実があったのですが、製品ドキュメントを読み進めるとできることがだんだん分かってきました。

カスタムコンテナイメージの作成

製品ドキュメントの「3.1. カスタマイズおよび最適化されたコンテナーイメージの作成」には下記の記載があります。

第3章 Red Hat build of Keycloak をコンテナー内で実行する | Red Hat Product Documentation

デフォルトの Red Hat build of Keycloak コンテナーイメージは、すぐに設定および最適化できる状態で出荷されます。 Red Hat build of Keycloak コンテナーを最適に起動するには、コンテナーのビルド中に build ステップを実行してイメージをビルドします。この手順を実行することで、後に続くコンテナーイメージの各起動フェーズで時間を節約できます。

ざっくり要約すると、Red Hat build of Keycloakのコンテナイメージをそのまま使うとPodの実行のたびに時間がかかるので、事前にプリビルドしたカスタムコンテナイメージを使用することで起動時間を短縮できる、ということのようです。

製品ドキュメントには下記のContainerfileのサンプルがあります。

FROM registry.redhat.io/rhbk/keycloak-rhel9:24 as builder

# Enable health and metrics support
ENV KC_HEALTH_ENABLED=true
ENV KC_METRICS_ENABLED=true

# Configure a database vendor
ENV KC_DB=postgres

WORKDIR /opt/keycloak
# for demonstration purposes only, please make sure to use proper certificates in production instead
RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore
RUN /opt/keycloak/bin/kc.sh build

FROM registry.redhat.io/rhbk/keycloak-rhel9:24
COPY --from=builder /opt/keycloak/ /opt/keycloak/

# change these values to point to a running postgres instance
ENV KC_DB=postgres
ENV KC_DB_URL=<DBURL>
ENV KC_DB_USERNAME=<DBUSERNAME>
ENV KC_DB_PASSWORD=<DBPASSWORD>
ENV KC_HOSTNAME=localhost
ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]

シンプルなマルチステージビルドの内容で、Red Hat提供のRed Hat build of Keycloakのコンテナイメージをベースイメージとし使用し、証明書やDBの設定を行う内容のようです。 元のイメージのまま起動した場合とカスタムコンテナイメージを使った場合でどれくらい時間短縮ができるのかについては、また別の機会に試してみたいと思います。

このカスタムコンテナイメージのビルドおよびテスト起動にPodmanを使うことがドキュメントに書かれています。 ちゃんとPodmanの出番があって安心しました。

開発またはテスト目的でコンテナ実行する

もうひとつのPodmanの利用用途がRed Hat build of Keycloakの開発またはテスト目的での実行です。これは製品ドキュメントの「3.3. 開発モードで Red Hat build of Keycloak を試用する」に記載があります。

3.3. 開発モードで Red Hat build of Keycloak を試用する | Red Hat Product Documentation

Red Hat提供のRed Hat build of Keycloakのコンテナイメージを使った実稼働環境での使用はサポートされませんが、開発またはテスト目的においてのみ使うことができる内容です。 podman runコマンドでいくつかのオプションをつけてRed Hat build of Keycloakのコンテナイメージを実行するだけのとても簡単なものです。 OpenShiftを用意するまでもなく、Red Hat build of Keycloakのコンテナイメージの実行を試したい場合には手軽な手段です。

では、実際にPodmanでRed Hat build of Keycloakのコンテナイメージを動かしてその内容を確認してみましょう。

繰り返しますが、PodmanでのRed Hat提供のRed Hat build of Keycloakのコンテナイメージの実行はサポートされる構成ではない点ご注意ください

Red Hat build of Keycloakのコンテナイメージの確認

Ecosystem Catalog上のRed Hat build of Keycloakのコンテナイメージ
Ecosystem Catalog上のRed Hat build of Keycloakのコンテナイメージ

Red Hat build of Keycloakのコンテナイメージはregistry.redhat.ioでホストされており、コンテナイメージをダウンロードするにはコンテナレジストリにログインする必要があります。

Red Hat build of Keycloakが含まれる製品の有効なサブスクリプションをお持ちのRed Hatアカウント、または評価版を使用中のRed Hatアカウント、等が必要です

podman loginコマンドでコンテナレジストリにログインします。

$ podman login registry.redhat.io

Red Hat build of Keycloakのコンテナイメージは必ずタグまで指定してpullする必要があります。本記事執筆時点での最新版は「keycloak-rhel9:24-10」です。

$ podman pull registry.redhat.io/rhbk/keycloak-rhel9:24-10

タグ指定なし(latest指定)の場合はイメージが見つからずエラーになります。

$ podman pull registry.redhat.io/rhbk/keycloak-rhel9
Trying to pull registry.redhat.io/rhbk/keycloak-rhel9:latest...
WARN[0000] Failed, retrying in 1s ... (1/3). Error: initializing source docker://registry.redhat.io/rhbk/keycloak-rhel9:latest: reading manifest latest in registry.redhat.io/rhbk/keycloak-rhel9: unsupported: This repository does not use the "latest" tag to track the most recent image and must be pulled with an explicit version or image reference. For more information, see: https://access.redhat.com/articles/4301321
WARN[0002] Failed, retrying in 1s ... (2/3). Error: initializing source docker://registry.redhat.io/rhbk/keycloak-rhel9:latest: reading manifest latest in registry.redhat.io/rhbk/keycloak-rhel9: unsupported: This repository does not use the "latest" tag to track the most recent image and must be pulled with an explicit version or image reference. For more information, see: https://access.redhat.com/articles/4301321
WARN[0003] Failed, retrying in 1s ... (3/3). Error: initializing source docker://registry.redhat.io/rhbk/keycloak-rhel9:latest: reading manifest latest in registry.redhat.io/rhbk/keycloak-rhel9: unsupported: This repository does not use the "latest" tag to track the most recent image and must be pulled with an explicit version or image reference. For more information, see: https://access.redhat.com/articles/4301321
Error: initializing source docker://registry.redhat.io/rhbk/keycloak-rhel9:latest: reading manifest latest in registry.redhat.io/rhbk/keycloak-rhel9: unsupported: This repository does not use the "latest" tag to track the most recent image and must be pulled with an explicit version or image reference. For more information, see: https://access.redhat.com/articles/4301321

OpenJDKの回*1*2で行ったようにイメージの確認をしてみます。podman imagespodman image treepodman historyを使います。

$ podman images
REPOSITORY                              TAG         IMAGE ID      CREATED      SIZE
registry.redhat.io/rhbk/keycloak-rhel9  24-10       559c3ef84129  13 days ago  461 MB
$ podman image tree registry.redhat.io/rhbk/keycloak-rhel9:24-10
Image ID: 559c3ef84129
Tags:     [registry.redhat.io/rhbk/keycloak-rhel9:24-10]
Size:     460.7MB
Image Layers
├── ID: 7a99878a1748 Size: 23.52MB
└── ID: 690b8207333e Size: 437.2MB Top Layer of: [registry.redhat.io/rhbk/keycloak-rhel9:24-10]
$ podman history registry.redhat.io/rhbk/keycloak-rhel9:24-10
ID            CREATED      CREATED BY                                     SIZE        COMMENT
559c3ef84129  13 days ago  /bin/sh -c #(nop) USER 1000                    437MB       FROM registry.redhat.io/ubi9/ubi-micro@sha256:826cf6250899228070dcd4eb0abd8667d0468a5fe0148d54bb513c912b06cee4
<missing>     13 days ago  /bin/sh -c mv -fZ /tmp/ubi.repo /etc/yum.r...  0B
<missing>     13 days ago  /bin/sh -c #(nop) USER root                    0B
<missing>     13 days ago  /bin/sh -c #(nop) USER 1000                    0B
<missing>     13 days ago  /bin/sh -c rm -f /tmp/tls-ca-bundle.pem        0B
<missing>     13 days ago  /bin/sh -c rm -f '/etc/yum.repos.d/odcs-31...  0B
<missing>     13 days ago  /bin/sh -c #(nop) USER root                    0B
...

Red Hat build of KeycloakのベースイメージはUBI-microが使われているようです。

UBI-microについては以前書いた記事がありますので、こちらを参考にしてください。 【UBI】Red Hatの新しい最軽量コンテナーイメージ:UBI Microの紹介 - 赤帽エンジニアブログ

Armホスト上でpullする場合

Red Hat build of Keycloakのコンテナイメージはamd64、ppc64le、s390xイメージしか提供されておらず、arm64版は提供されていません。 Apple Silicon Macの場合、そのままではpullできずエラーになります。

% podman pull registry.redhat.io/rhbk/keycloak-rhel9:24-10
Trying to pull registry.redhat.io/rhbk/keycloak-rhel9:24-10...
Error: choosing an image from manifest list docker://registry.redhat.io/rhbk/keycloak-rhel9:24-10: no image found in manifest list for architecture "arm64", variant "v8", OS "linux"

--archオプションに続けてアーキテクチャーを指定することでpullが可能になります。

% podman pull --arch amd64 registry.redhat.io/rhbk/keycloak-rhel9:24-10

PodmanでRed Hat build of Keycloakのコンテナイメージを実行する

ここからは普段使っているApple Silicon Mac上のPodman machineで実行してみます。

ドキュメントに記載のpodman runコマンドは下記のとおりです

% podman run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin keycloak-rhel9:24-10 start-dev
  • -e KEYCLOAK_ADMIN:管理ユーザーのユーザー名を指定
  • -e KEYCLOAK_ADMIN_PASSWORD:管理ユーザーのパスワードを指定
  • start-dev:開発モードで実行するためのスイッチ

上記のコマンドを実行した場合、Podman machineのメモリ設定がデフォルトの2GBのままだとエラーになり起動しません。Podman machine以外の環境でエラーになる場合も空きメモリに余裕があるかどうか確認ください。

% podman run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin keycloak-rhel9:24-10 start-dev
WARNING: image platform (linux/amd64) does not match the expected platform (linux/arm64)
Updating the configuration and installing your custom providers, if any. Please wait.
2024-06-11 20:30:36,636 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index org.apache.tools.ant.Task: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,676 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index org.springframework.core.io.DefaultResourceLoader: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,677 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index org.springframework.core.io.ResourceLoader: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,679 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index org.springframework.core.io.Resource: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,703 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index io.mashona.logwriting.ArrayStore: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,705 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index org.apache.activemq.artemis.core.journal.RecordInfo: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,705 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index org.apache.activemq.artemis.core.journal.Journal: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,711 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index jakarta.jms.XAConnection: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,711 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index jakarta.jms.XASession: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,712 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index jakarta.jms.XAConnectionFactory: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:30:36,747 WARN  [io.qua.dep.ind.IndexWrapper] (build-68) Failed to index jakarta.jms.Connection: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
/opt/keycloak/bin/kc.sh: line 161:    76 Killed                  'java' -Dkc.config.build-and-exit=true '-XX:MetaspaceSize=96M' '-XX:MaxMetaspaceSize=256m' '-Dfile.encoding=UTF-8' '-Dsun.stdout.encoding=UTF-8' '-Dsun.err.encoding=UTF-8' '-Dstdout.encoding=UTF-8' '-Dstderr.encoding=UTF-8' '-XX:+ExitOnOutOfMemoryError' '-Djava.security.egd=file:/dev/urandom' '-XX:+UseParallelGC' '-XX:GCTimeRatio=4' '-XX:AdaptiveSizePolicyWeight=90' '-XX:FlightRecorderOptions=stackdepth=512' '-XX:MinHeapFreeRatio=10' '-XX:MaxHeapFreeRatio=20' '-Xms64m' '-Xmx512m' '--add-opens=java.base/java.util=ALL-UNNAMED' '--add-opens=java.base/java.util.concurrent=ALL-UNNAMED' '--add-opens=java.base/java.security=ALL-UNNAMED' -Dkc.home.dir='/opt/keycloak/bin/..' -Djboss.server.config.dir='/opt/keycloak/bin/../conf' -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dpicocli.disable.closures=true -Dquarkus-log-max-startup-records=10000 -cp '/opt/keycloak/bin/../lib/quarkus-run.jar' io.quarkus.bootstrap.runner.QuarkusEntryPoint --profile=dev start-dev

Podman machineのメモリの割り当てを増やすには、一度Podman machineを止めて設定を変更する必要があります。 Podman machineのメモリの割り当てメモリの変更はpodman machine setコマンドに続けて--memoryオプションを使います。指定する数値はMiBで指定します。

% podman machine ls
NAME                     VM TYPE     CREATED       LAST UP            CPUS        MEMORY      DISK SIZE
podman-machine-default*  applehv     9 days ago    Currently running  5           2GiB        100GiB
% podman machine stop
% podman machine set --memory 10240
% podman machine ls
NAME                     VM TYPE     CREATED       LAST UP            CPUS        MEMORY      DISK SIZE
podman-machine-default*  applehv     9 days ago    Currently running  5           10GiB       100GiB

Podman machineの割り当てメモリを変更後、再度podman runコマンドを実行します。今度は無事にコンテナが起動しました。

  • 無事に起動することが確認できればpodman runコマンドに-dオプションをつけてバックグラウンドで起動するように変更してもよいでしょう
$ podman run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin keycloak-rhel9:24-10 start-dev
WARNING: image platform (linux/amd64) does not match the expected platform (linux/arm64)
Updating the configuration and installing your custom providers, if any. Please wait.
2024-06-11 20:36:15,582 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index org.springframework.core.io.DefaultResourceLoader: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,593 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index org.springframework.core.io.ResourceLoader: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,612 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index org.apache.tools.ant.Task: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,631 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index org.springframework.core.io.Resource: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,640 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index jakarta.jms.XAConnection: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,641 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index jakarta.jms.XASession: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,641 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index jakarta.jms.XAConnectionFactory: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,643 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index jakarta.jms.Connection: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,647 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index io.mashona.logwriting.ArrayStore: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,648 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index org.apache.activemq.artemis.core.journal.RecordInfo: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21
2024-06-11 20:36:15,649 WARN  [io.qua.dep.ind.IndexWrapper] (build-40) Failed to index org.apache.activemq.artemis.core.journal.Journal: Class does not exist in ClassLoader QuarkusClassLoader:Deployment Class Loader: PROD for keycloak@3ecedf21

2024-06-11 20:37:14,933 INFO  [io.qua.dep.QuarkusAugmentor] (main) Quarkus augmentation completed in 72776ms
2024-06-11 20:37:18,271 INFO  [org.keycloak.quarkus.runtime.hostname.DefaultHostnameProvider] (main) Hostname settings: Base URL: <unset>, Hostname: <request>, Strict HTTPS: false, Path: <request>, Strict BackChannel: false, Admin URL: <unset>, Admin: <request>, Port: -1, Proxied: false
2024-06-11 20:37:20,669 WARN  [io.quarkus.agroal.runtime.DataSources] (JPA Startup Thread) Datasource <default> enables XA but transaction recovery is not enabled. Please enable transaction recovery by setting quarkus.transaction-manager.enable-recovery=true, otherwise data may be lost if the application is terminated abruptly
2024-06-11 20:37:21,420 WARN  [org.infinispan.CONFIG] (keycloak-cache-init) ISPN000569: Unable to persist Infinispan internal caches as no global state enabled
2024-06-11 20:37:21,629 INFO  [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000556: Starting user marshaller 'org.infinispan.jboss.marshalling.core.JBossUserMarshaller'
2024-06-11 20:37:22,566 INFO  [org.keycloak.broker.provider.AbstractIdentityProviderMapper] (main) Registering class org.keycloak.broker.provider.mappersync.ConfigSyncEventListener
2024-06-11 20:37:22,599 INFO  [org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory] (main) Node name: node_120547, Site name: null
2024-06-11 20:37:24,429 INFO  [org.keycloak.quarkus.runtime.storage.legacy.liquibase.QuarkusJpaUpdaterProvider] (main) Initializing database schema. Using changelog META-INF/jpa-changelog-master.xml

UPDATE SUMMARY
Run:                        124
Previously run:               0
Filtered out:                 0
-------------------------------
Total change sets:          124

2024-06-11 20:37:29,282 INFO  [org.keycloak.services] (main) KC-SERVICES0050: Initializing master realm
2024-06-11 20:37:32,370 INFO  [org.keycloak.services] (main) KC-SERVICES0009: Added user 'admin' to realm 'master'
2024-06-11 20:37:32,662 INFO  [io.quarkus] (main) Keycloak 24.0.5.redhat-00001 on JVM (powered by Quarkus 3.8.4.redhat-00002) started in 17.107s. Listening on: http://0.0.0.0:8080
2024-06-11 20:37:32,664 INFO  [io.quarkus] (main) Profile dev activated.
2024-06-11 20:37:32,664 INFO  [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, jdbc-h2, keycloak, narayana-jta, reactive-routes, resteasy-reactive, resteasy-reactive-jackson, smallrye-context-propagation, vertx]
2024-06-11 20:37:32,674 WARN  [org.keycloak.quarkus.runtime.KeycloakMain] (main) Running the server in development mode. DO NOT use this configuration in production.

コンテナの起動後は、ブラウザでhttp://localhost:8080にアクセスし、管理者ユーザーのIDとパスワードでログインします。

Red Hat build of Keycloakのログイン画面
Red Hat build of Keycloakのログイン画面

Red Hat build of Keycloakの管理コンソール
Red Hat build of Keycloakの管理コンソール
Red Hat build of Keycloakの画面にアクセスできました。

余談ですが、Apple Silicon MacでRed Hat build of Keycloakのコンテナイメージ(amd64)を実行する場合はエミュレーションモードでの実行になります。 Podman v5.1以降はmacOS版のPodman machineのエミュレーションモードはデフォルトでRosettaが使用されます。 Red Hat build of Keycloakの起動時間を比べたところ、

  • Rosetta使用の場合:1分程度
  • qemu-user-static使用の場合:2分程度

と2倍くらいの時間の差があります。起動後の負荷テストなどは行っていませんが、実際の稼働のパフォーマンスなどにも違いは出てくると思われます。 このRosetta機能は私がPull Requestを書いて実装したのですが、こうやって実際に役に立つ場面があると頑張った甲斐があるなと感動します。 PodmanのRosettaについての解説は下記の記事を参照ください。

rheb.hatenablog.com

まとめ

Red Hat build of Keycloakのコンテナイメージを使ってテスト目的でのPodmanの実行を行うことができました。 実稼働目的ではないとはいえ、まずはお試しでRed Hat build of Keycloak実行してみる手段としてはとても有用です。 この次のステップとしては、外部データーベースを同じくコンテナで起動してRed Hat build of Keycloakから繋いでみるとか、Podmanの環境で高可用性のテストなんかもできるかもしれません(あくまで妄想ですが)。

アップストリームのKeycloakではPodmanを使ったスタートガイドなども実はあります。

www.keycloak.org

「Podmanではじめる〜」本シリーズはRed Hat製品を対象とするのでRed Hat build of Keycloakに対象を絞って紹介しました。 OpenShiftを使わずにRed Hat build of Keycloakをコンテナで実行できることが分かったので、さらに使い込んでRed Hat build of Keycloakのことを理解していきたいと思います。

* 各記事は著者の見解によるものでありその所属組織を代表する公式なものではありません。その内容については非公式見解を含みます。