title: Setting up realms in Keycloak during kubernetes helm install
body: <p>I'm trying to get <code>keycloak</code> set up as a helm chart requirement to run some integration tests. I can get it to bring it up and run it, but I can't figure out how to set up the realm and client I need. I've switched over to the 1.0.0 stable release that came out today:</p>
  
  <p><a href="https://github.com/kubernetes/charts/tree/master/stable/keycloak" rel="nofollow noreferrer">https://github.com/kubernetes/charts/tree/master/stable/keycloak</a></p>
  
  <p>I wanted to use the <code>keycloak.preStartScript</code> defined in the chart and use the <code>/opt/jboss/keycloak/bin/kcadm.sh</code> admin script to do this, but apparently by "pre start" they mean before the server is brought up, so <code>kcadm.sh</code> can't authenticate. If I leave out the <code>keycloak.preStartScript</code> I can shell into the keycloak container and run the <code>kcadm.sh</code> scripts I want to use after it's up and running, but they fail as part of the pre start script. </p>
  
  <p>Here's my <code>requirements.yaml</code> for my chart:</p>
  
  <pre><code>dependencies:
  - name: keycloak
    repository: https://kubernetes-charts.storage.googleapis.com/
    version: 1.0.0
  </code></pre>
  
  <p>Here's my <code>values.yaml</code> file for my chart:</p>
  
  <pre><code>keycloak:
    keycloak:
      persistence:
        dbVendor: H2
        deployPostgres: false
      username: 'admin'
      password: 'test'
      preStartScript: |
        /opt/jboss/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080/auth --realm master --user admin --password 'test'
        /opt/jboss/keycloak/bin/kcadm.sh create realms -s realm=foo -s enabled=true -o
        CID=$(/opt/jboss/keycloak/bin/kcadm.sh create clients -r foo -s clientId=foo -s 'redirectUris=["http://localhost:8080/*"]' -i)
        /opt/jboss/keycloak/bin/kcadm.sh get clients/$CID/installation/providers/keycloak-oidc-keycloak-json
    persistence:
      dbVendor: H2
      deployPostgres: false
  </code></pre>
  
  <p>Also a side annoyance is that I need to define the persistence settings in both places or it either fails or brings up <code>postgresql</code> in addition to <code>keycloak</code></p>