<p>I want to configure a custom theme for login, register and forgot password pages in keycloak on kubernetes.</p>
<p>I am using the following url and configuration for keycloak on kubernetes.</p>
<p><a href="https://www.keycloak.org/getting-started/getting-started-kube" rel="nofollow noreferrer">https://www.keycloak.org/getting-started/getting-started-kube</a></p>
<pre><code>            apiVersion: v1
            kind: Service
            metadata:
            name: keycloak
            labels:
                app: keycloak
            spec:
            ports:
            - name: http
                port: 8080
                targetPort: 8080
            selector:
                app: keycloak
            type: LoadBalancer
            ---
            apiVersion: apps/v1
            kind: Deployment
            metadata:
            name: keycloak
            namespace: default
            labels:
                app: keycloak
            spec:
            replicas: 1
            selector:
                matchLabels:
                app: keycloak
            template:
                metadata:
                labels:
                    app: keycloak
                spec:
                containers:
                - name: keycloak
                    image: quay.io/keycloak/keycloak:12.0.4
                    env:
                    - name: KEYCLOAK_USER
                    value: &quot;admin&quot;
                    - name: KEYCLOAK_PASSWORD
                    value: &quot;admin&quot;
                    - name: PROXY_ADDRESS_FORWARDING
                    value: &quot;true&quot;
                    ports:
                    - name: http
                    containerPort: 8080
                    - name: https
                    containerPort: 8443
                    readinessProbe:
                    httpGet:
                        path: /auth/realms/master
                        port: 8080
</code></pre>
<p>Please suggest me any existing blog url or existing solution.</p>

Santosh Shinde
<p>The approach that I have used on the past was to first create a .tar file (<em>e.g.,</em> <code>custom_theme.tar</code>) with the custom themes to be used in Keycloak. Then mount volume to the folder where the Keycloak themes are stored (<em>i.e.,</em> <code>/opt/jboss/keycloak/themes/my_custom_theme</code>), and copy the .tar file with the custom themes from a local folder into the Keycloak container.</p>
<p>The helm char folder structure:</p>
<pre><code>Chart.yaml      custom_theme.tar    templates       values.yaml
</code></pre>
<p>the content of :</p>
<p><strong>values.yaml:</strong></p>
<pre><code>password: adminpassword
</code></pre>
<p>The template folder structure:</p>
<pre><code>customThemes-configmap.yaml ingress.yaml            service.yaml
deployment.yaml         secret.yaml
</code></pre>
<p>the content of :</p>
<p><strong>customThemes-configmap.yaml</strong></p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: customthemes-configmap
binaryData:
  custom_theme.tar: |-
    {{ .Files.Get &quot;custom_theme.tar&quot; | b64enc}}
</code></pre>
<p><strong>ingress.yaml</strong></p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: keycloak
spec:
  tls:
    - hosts:
      - keycloak-sprint01.demo
  rules:
  - host: keycloak-sprint01.demo
    http:
      paths:
      - backend:
          serviceName: keycloak
          servicePort: 8080
</code></pre>
<p><strong>service.yaml</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: keycloak
  labels:
    app: keycloak
spec:
  ports:
  - name: http
    port: 8080
    targetPort: 8080
  selector:
    app: keycloak
  type: LoadBalancer
</code></pre>
<p><strong>secret.yaml</strong></p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: keycloak-password
type: Opaque
stringData:
  password: {{.Values.password}}
</code></pre>
<p><strong>deployment.yaml</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: keycloak
  namespace: default
  labels:
    app: keycloak
spec:
  replicas: 1
  selector:
    matchLabels:
      app: keycloak
  template:
    metadata:
      labels:
        app: keycloak
    spec:
      containers:
      - name: keycloak
        image: quay.io/keycloak/keycloak:10.0.1
        env:
        - name: KEYCLOAK_USER
          value: &quot;admin&quot;
        - name: KEYCLOAK_PASSWORD
          valueFrom:
            secretKeyRef:
              name: keycloak-password
              key: password
        - name: PROXY_ADDRESS_FORWARDING
          value: &quot;true&quot;
        - name: DB_VENDOR
          value: &quot;h2&quot;
        - name: JAVA_TOOL_OPTIONS
          value: -Dkeycloak.profile.feature.scripts=enabled
        ports:
        - name: http
          containerPort: 8080
        - name: https
          containerPort: 8443
        readinessProbe:
          httpGet:
            path: /auth/realms/master
            port: 8080
        volumeMounts:
        - mountPath: /opt/jboss/keycloak/themes/my_custom_theme
          name: shared-volume            
          
      initContainers:
        - name: init-customtheme
          image: busybox:1.28
          command: ['sh', '-c', 'cp -rL /CustomTheme/custom_theme.tar /shared &amp;&amp; cd /shared/ &amp;&amp; tar -xvf custom_theme.tar &amp;&amp; rm -rf custom_theme.tar']
          volumeMounts:
          - mountPath: /shared
            name: shared-volume          
          - mountPath: /CustomTheme
            name: theme-volume
                   
      volumes:
      - name: shared-volume
        emptyDir: {}
      - name: theme-volume
        configMap:
          name: customthemes-configmap 
</code></pre>
<hr />
<p>I am not claiming that this is the best way to do it, I am not an expert in Kubernetes or helm. A Git repo containing the aforementioned files can be found <a href="https://github.com/dreamcrash/StackOverflow-/tree/main/Keycloak/minikube" rel="noreferrer">here</a>.</p>
