如何在 kubernetes 上为 keyCloak 配置自定义主题 [英] How to configure custom themes for keyCloak on kubernetes

查看:56
本文介绍了如何在 kubernetes 上为 keyCloak 配置自定义主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 kubernetes 上的 keycloak 中为登录、注册和忘记密码页面配置一个自定义主题.

I want to configure a custom theme for login, register and forgot password pages in keycloak on kubernetes.

我在 kubernetes 上为 keycloak 使用以下 URL 和配置.

I am using the following url and configuration for keycloak on kubernetes.

https://www.keycloak.org/getting-started/getting-started-kube

            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: "admin"
                    - name: KEYCLOAK_PASSWORD
                    value: "admin"
                    - name: PROXY_ADDRESS_FORWARDING
                    value: "true"
                    ports:
                    - name: http
                    containerPort: 8080
                    - name: https
                    containerPort: 8443
                    readinessProbe:
                    httpGet:
                        path: /auth/realms/master
                        port: 8080

请向我推荐任何现有的博客网址或现有的解决方案.

Please suggest me any existing blog url or existing solution.

推荐答案

我过去使用的方法是首先创建一个 .tar 文件(例如 custom_theme.tar) 与要在 Keycloak 中使用的自定义主题.然后将卷挂载到存储 Keycloak 主题的文件夹(ie, /opt/jboss/keycloak/themes/my_custom_theme),并复制带有自定义的 .tar 文件主题从本地文件夹到 Keycloak 容器.

The approach that I have used on the past was to first create a .tar file (e.g., custom_theme.tar) with the custom themes to be used in Keycloak. Then mount volume to the folder where the Keycloak themes are stored (i.e., /opt/jboss/keycloak/themes/my_custom_theme), and copy the .tar file with the custom themes from a local folder into the Keycloak container.

helm char 文件夹结构:

The helm char folder structure:

Chart.yaml      custom_theme.tar    templates       values.yaml

内容:

values.yaml:

password: adminpassword

模板文件夹结构:

customThemes-configmap.yaml ingress.yaml            service.yaml
deployment.yaml         secret.yaml

内容:

customThemes-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: customthemes-configmap
binaryData:
  custom_theme.tar: |-
    {{ .Files.Get "custom_theme.tar" | b64enc}}

ingress.yaml

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

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: keycloak
  labels:
    app: keycloak
spec:
  ports:
  - name: http
    port: 8080
    targetPort: 8080
  selector:
    app: keycloak
  type: LoadBalancer

secret.yaml

apiVersion: v1
kind: Secret
metadata:
  name: keycloak-password
type: Opaque
stringData:
  password: {{.Values.password}}

deployment.yaml

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: "admin"
        - name: KEYCLOAK_PASSWORD
          valueFrom:
            secretKeyRef:
              name: keycloak-password
              key: password
        - name: PROXY_ADDRESS_FORWARDING
          value: "true"
        - name: DB_VENDOR
          value: "h2"
        - 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 && cd /shared/ && tar -xvf custom_theme.tar && 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 


我并不是说这是最好的方法,我不是 Kubernetes 或掌舵方面的专家.可以在此处找到包含上述文件的 Git 存储库.


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 here.

这篇关于如何在 kubernetes 上为 keyCloak 配置自定义主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆