如何在kubernetes上为keycloak配置自定义主题

0x6upsns  于 2023-01-01  发布在  Kubernetes
关注(0)|答案(2)|浏览(224)

我想在kubernetes上的keycloak中为登录、注册和忘记密码页面配置一个自定义主题。
我在kubernetes上为keycloak使用以下url和配置。
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

请建议我任何现有的博客网址或现有的解决方案。

vcirk6k6

vcirk6k61#

我过去使用的方法是首先创建一个.tar文件(* 例如,* custom_theme.tar),其中包含要在Keycloak中使用的自定义主题。然后将卷挂载到存储Keycloak主题的文件夹(* 即,* /opt/jboss/keycloak/themes/my_custom_theme),并将包含自定义主题的.tar文件从本地文件夹复制到Keycloak容器中。
helm char文件夹结构:

Chart.yaml      custom_theme.tar    templates       values.yaml

内容:

值。yaml:

password: adminpassword

模板文件夹结构:

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

内容:

自定义主题-配置Map.yaml

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

入口.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

服务.yaml

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

秘密.yaml

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

部署.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或helm方面的Maven。包含上述文件的Git repo可以在here中找到。

ulmd4ohb

ulmd4ohb2#

你可以用initContainers做一个主题图片,这个主题可以在helm chart文件夹之外维护

initContainers: |
    - name: keycloak-theme-provider
      image: docker.io/my-theme:1.0
      imagePullPolicy: IfNotPresent
      command:
        - sh
      args:
        - -c
        - |
          echo "Copying theme..."
          cp -R /my-theme/* /theme
      volumeMounts:
        - name: theme
          mountPath: /theme

extraVolumeMounts:
  - name: theme
    mountPath: /opt/jboss/keycloak/themes/my-theme

extraVolumes:
  - name: theme
    emptyDir: {}

装卸工图像码

FROM busybox

COPY src/themes/ /my-theme

相关问题