how to persist keycloak in kubernetes custom themes

3/7/2020

I have tried to persist the custom themes through gcepersistentdisk but when I enter the administration console it does not load anything, and checking the folder /opt/jboss/keycloak/themes is empty.

Also try creating a custom docker image (Dockerfile) by adding the following line to copy the custom themas.

COPY /source-folder/login /opt/jboss/keycloak/themes/login

although in the folder /opt/jboss/keycloak/themes I can see the new login folder, when I access the administration console I cannot see the custom theme login.

I can only view the custom theme when I do it with the following kubernet commands:

  1. kubectl exec POD --namespace keycloak - mkdir /opt/jboss/keycloak/themes/login

  2. kubectl cp keycloak/login keycloak/POD:/opt/jboss/keycloak/themes/login

With the previous commands if I can see the custom theme login in the administration console

I have tried using gcePersistentDisk as follows:

spec:
  containers:
    - name: keycloak
   ...
   volumeMounts:
     - mountPath: /opt/jboss/keycloak/themes
       name: test-volume

  volumes:
    - name: test-volume
      gcePersistentDisk:
        pdName: pd-name
        fsType: ext4

In what way can I persist with custom themes when the pod restarts?

-- Juanes30
google-cloud-platform
keycloak
kubernetes

2 Answers

3/7/2020

Create a StorageClass and a PersistentVolumeClaim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: ssd-sc  # specify the storage class created below
  resources:
    requests:
      storage: 10Gi

---

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: ssd-sc 
provisioner: kubernetes.io/gce-pd
reclaimPolicy: Retain # Retain storage even if we delete PVC
parameters:
  type: pd-ssd # ssd

Create a Pod to use PersistentVolumeClaim

apiVersion: v1
kind: Pod
metadata:
  name: task-pv-pod
spec:
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
        claimName: nfs-pvc
  containers:
    - name: task-pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: task-pv-storage
-- Arghya Sadhu
Source: StackOverflow

3/9/2020

As I understand each theme should have own folder. It should be themes/mytheme/login instead of themes/login. For example, your local structure may look like:

Dockerfile
themes
|-mytheme
  |-account
  |-admin
  |-login
    |-resources 
      |-css
      |-img
    |-theme.properties
  |-welcome

Docker file may look like:

FROM jboss/keycloak:8.0.1
ADD ./themes /opt/jboss/keycloak/themes/

Build a docker image, run, then go to Realm Settings -> Themes and select your theme.

-- Yuriy P
Source: StackOverflow