使用导入的领域配置创建 Keycloak 部署

Create Keycloak deployment with imported realm configuration

我正在尝试创建一个 Keycloak 部署,其配置是从位于 ./import/realm.json 的本地文件导入的。

文件夹结构:

但是,在应用部署时出现此错误:

 FATAL [org.keycloak.services] (ServerService Thread Pool -- 59) Error during startup: java.lang.RuntimeException: java.io.FileNotFoundException: /import/realm.json (No such file or directory)

这是我正在尝试创建的部署 (keycloak-deploy.yml):

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: keycloak-deployment
  name: keycloak-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: keycloak-deployment
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: keycloak-deployment
    spec:
      containers:
      - image: jboss/keycloak:latest
        name: keycloak
        env:
          - name: KEYCLOAK_USER
            value: admin
          - name: KEYCLOAK_PASSWORD
            value: superSecret
          - name: KEYCLOAK_IMPORT
            value: /import/realm.json
        ports:
          - containerPort: 8081
        readinessProbe:
          httpGet:
            path: /auth/realms/master
            port: 8081
        resources: {}
status: {}

我是 Kubernetes 的初学者,非常感谢任何帮助,谢谢!

我按照评论中的内容进行了操作(感谢@Andrew Skorkin)。它是这样工作的:

  • 部署与服务:
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: keycloak-deployment
  name: keycloak-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: keycloak-deployment
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: keycloak-deployment
    spec:
      containers:
      - image: jboss/keycloak:latest
        name: keycloak
        env:
          - name: KEYCLOAK_USER
            value: admin
          - name: KEYCLOAK_PASSWORD
            value: superSecret
          - name: KEYCLOAK_IMPORT
            value: /import/realm.json
        ports:
          - name: http
            containerPort: 8081
        volumeMounts:
          - name: keycloak-volume
            mountPath: /import
        readinessProbe:
          httpGet:
            path: /auth/realms/master
            port: 8081
          initialDelaySeconds: 30
          timeoutSeconds: 30
        resources: {}
      volumes:
        - name: keycloak-volume
          configMap:
            name: keycloak-configmap
status: {}
---
apiVersion: v1
kind: Service
metadata:
  name: keycloak-service
spec:
  selector:
    app: keycloak-service
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
  • 配置图:
apiVersion: v1
data:
  realm.json: |
    {json_content}
kind: ConfigMap
metadata:
  name: keycloak-configmap

json_content 包含 realm.json 数据。我从一个工作的 keycloak 实例中导出数据(用 docker-compose 制作)。