<p>I am trying to run KeyCloak on Kubernetes using PostgreSQL as a database.</p>
<p>The files I am referring to are on the <a href="https://github.com/peterzandbergen/keycloak-kubernetes" rel="nofollow noreferrer">peterzandbergen/keycloak-kubernetes</a> project on GitHub.</p>
<p>I used <code>kompose</code> to generate the <code>yaml</code> files, as a staring point, using the files that <a href="https://github.com/jboss-dockerfiles/keycloak/tree/master/docker-compose-examples" rel="nofollow noreferrer">jboss</a> published.</p>
<p>PostgreSQL is started first using:</p>
<pre class="lang-sh prettyprint-override"><code>./start-postgres.sh
</code></pre>
<p>Then I try to start KeyCloak:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl create -f keycloak-deployment.yaml
</code></pre>
<p>The KeyCloak pod stops because it cannot connect to the database with the error:</p>
<pre><code>10:00:40,652 SEVERE [org.postgresql.Driver] (ServerService Thread Pool -- 58) Error in url: jdbc:postgresql://172.17.0.4:tcp://10.101.187.192:5432/keycloak
</code></pre>
<p>The full log can be found on <a href="https://github.com/peterzandbergen/keycloak-kubernetes" rel="nofollow noreferrer">github</a>. This is also the place to look at the yaml files that I use to create the deployment and the services.</p>

Peter Zandbergen
<p>After some experimenting I found out that using the name <strong>postgres</strong> in the keycloak-deployment.yaml file </p>

<pre><code>- env:
    - name: DB_ADDR
      value: postgres
</code></pre>

<p>messes things up and results in a strange expansion. After replacing this part of the yaml file with:</p>

<pre><code>- env:
    - name: DB_ADDR
      value: postgres-keycloak
</code></pre>

<p>makes it work fine. This also requires changing the postgres-service.yaml file. The new versions of the files are in <a href="https://github.com/peterzandbergen/keycloak-kubernetes" rel="nofollow noreferrer">github</a>.</p>
